content
stringlengths
1
1.04M
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc1798.vhd,v 1.2 2001-10-26 16:29:43 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c07s01b00x00p02n01i01798ent IS END c07s01b00x00p02n01i01798ent; ARCHITECTURE c07s01b00x00p02n01i01798arch OF c07s01b00x00p02n01i01798ent IS BEGIN TESTING: PROCESS variable x : integer := 3; variable y : integer := 5; variable z : integer := 9; BEGIN if -x + z < y + x and x * z > y - x then -- No_failure_here x := x - z; end if; assert NOT(x=-6) report "***PASSED TEST: c07s01b00x00p02n01i01798" severity NOTE; assert (x=-6) report "***FAILED TEST: c07s01b00x00p02n01i01798 - The expression is a valid expression according to the rules of the syntactic diagram." severity ERROR; wait; END PROCESS TESTING; END c07s01b00x00p02n01i01798arch;
---------------------------------------------------------------------------------- -- Engineer: Mike Field <[email protected]> -- -- Description: Generate I2S audio stream and master clock for the PMODI2S. -- The chip is a Cirrus Logic CS4344 DAC -- -- Drive with a 100MHz clock for 48,828 samples per second -- -- 'accepted' will strobe when 'data_l' and 'data_r' are latched -- -- 'data_l' and 'data_r' are assumed to be signed values. ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity i2s_output is Port ( clk : in STD_LOGIC; data_l : in STD_LOGIC_VECTOR (15 downto 0); data_r : in STD_LOGIC_VECTOR (15 downto 0); accepted : out STD_LOGIC; i2s_sd : out STD_LOGIC; i2s_lrclk : out STD_LOGIC; i2s_sclk : out STD_LOGIC; i2s_mclk : out STD_LOGIC); end i2s_output; architecture Behavioral of i2s_output is signal advance : std_logic := '0'; signal divider : unsigned( 4 downto 0) := (others => '0'); signal step : unsigned( 5 downto 0) := (others => '0'); signal shift_out : std_logic_vector(16 downto 0) := (others => '0'); signal hold_r : std_logic_vector(15 downto 0) := (others => '0'); begin i2s_lrclk <= std_logic(step(5)); i2s_mclk <= std_logic(divider(1)); i2s_sclk <= std_logic(step(0)); i2s_sd <= shift_out(shift_out'high); process(clk) begin if rising_edge(clk) then accepted <= '0'; if advance = '1' then if step(0) = '1' then shift_out <= shift_out(shift_out'high-1 downto 0) & '1'; if step(5 downto 1) = "01111" then shift_out(15 downto 0) <= hold_r; elsif step(5 downto 1) = "11111" then shift_out(15 downto 0) <= data_l xor x"8000"; hold_r <= data_r xor x"8000"; accepted <= '1'; end if; end if; step <= step + 1; end if; if divider = 0 then advance <= '1'; else advance <= '0'; end if; divider <= divider + 1; end if; end process; end Behavioral;
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity RD_Mux is Port ( RfDest : in STD_LOGIC; RD : in STD_LOGIC_VECTOR (5 downto 0); nRD : out STD_LOGIC_VECTOR (5 downto 0)); end RD_Mux; architecture Behavioral of RD_Mux is begin process(RfDest, RD) begin if (RfDest = '1') then nRD <= "001111"; else nRD <= RD; end if; end process; end Behavioral;
`protect begin_protected `protect version = 1 `protect encrypt_agent = "XILINX" `protect encrypt_agent_info = "Xilinx Encryption Tool 2014" `protect key_keyowner = "Cadence Design Systems.", key_keyname= "cds_rsa_key", key_method = "rsa" `protect encoding = (enctype = "BASE64", line_length = 76, bytes = 64) `protect key_block V1qQ/dO68m3x2EnMAwJABWD40Yxb848s2Qek5JN6KRC/8MOasBnl0mKJFELD1NDie9fgcLxKhTAj JB47bHQVCQ== `protect key_keyowner = "Mentor Graphics Corporation", key_keyname= "MGC-VERIF-SIM-RSA-1", key_method = "rsa" `protect encoding = (enctype = "BASE64", line_length = 76, bytes = 128) `protect key_block ZBudBrfNpokdq5xFNGqXytmiQloUs6dF+EdzNphIulqp+iN9Dh2Olb6+/Zz5NnOh+T+yFlI+3EKq fJNCNB3gIRZkLI3sKG4B5YfI78fTh/PEBcP985aHFMXYTTC08kh+2Il6DiHxObU+lX8F7Dso5+Wa gNxPwIFhAxn+H2OZ5I8= `protect key_keyowner = "Xilinx", key_keyname= "xilinx_2014_03", key_method = "rsa" `protect encoding = (enctype = "BASE64", line_length = 76, bytes = 256) `protect key_block GmbFyNHdf8DhwMpH7fWVVMB6RX5cf+kYqOpoXXlze1gf4WXTwlC/GRC+Qh8WWDRIG4twF7BPe80d aAFD14dWPQrUvvPpMbp186WMiP2l0IT0ANnP5WeywAF73KHunQ7JY0Ny2iFCT37tj88rpxj4CWwZ artlcK/B7NAm0d3Y7Au2seDBqk3pKXqTVbt1rq9yBtZBvUvYI+lUOriuf/3avIAo5wQagQ26F5Cu My/yOKHKl+fu8CkLzLxyFjaHoYOMUPaxELRBHg5IST0ywjrYgaoqbjVLZPmOcamnEdEU42k09XgS nQ3Lzr9PQ0NrLGwBqeQkwC2p8Esy0mioYFSH+Q== `protect key_keyowner = "Synopsys", key_keyname= "SNPS-VCS-RSA-1", key_method = "rsa" `protect encoding = (enctype = "BASE64", line_length = 76, bytes = 128) `protect key_block BiYn69Saf66vv8xlV2GIFeO/YWzj+WsH4Rw/DKXfRd7eU7R4GIEBJEgGucn5o6L399cOgsneivWK Fbi/jecG7bmyk2DhFtKBXcluVjfRxVCClVp44Ibt0GgONl0x9gCl/GI2ESRcru8u5QQIWh8SpQNH 1btlIAezhDHI9wk0D+k= `protect key_keyowner = "Aldec", key_keyname= "ALDEC08_001", key_method = "rsa" `protect encoding = (enctype = "BASE64", line_length = 76, bytes = 256) `protect key_block S4p72U0eTTEWNqkxciCGDR9vJZrZMqzfzH/g7Kmg9Vniw+/g29OTnZpdoQGdQwjzARF68Yw9Ldvc DAjHvXnjqiGznsYU6Lp1uDUDAY/nSC18an79HynEkeRsTsFk5wcwE/2MPv2FGrj43e82Emwzjmsm 1pIZFCji0T1tcSbnp1Umxn6ZTgPaGrfp4vAFSjXAyB5OlSFsbs3RzYKXr9gJIixQYe1bzU/Uj02j dl90KVMterr0wotEawN4daHqcjx6e+1W+H/hu/AvCmdcVIYw8sCqx3xElFyRsJq9h+HtfJP2DArh wwadKFMOEvD7d3OZ5xtxmumXo5pt9fEGEYnpcA== `protect data_method = "AES128-CBC" `protect encoding = (enctype = "BASE64", line_length = 76, bytes = 6272) `protect data_block GHHGRuu9Y64x63XFmJ//1acflUPbhdVVg6gQZT6LmZspQY1s1PrswU0nEKRZk+C5Y3gVrrMpgyYf 183P2BXfDGQsMsTqtzI5660XQKrHm40SXET5jVZZ2mBYW/tFpUe8DeUs0Ly0neDoYtXnyNLj69uD Hlj46ocd2zroS1d+7RMqCwSmsWfCE9p56Vr9kQxRFkiP9uIoaQUztS6WV5FOopof/4Rcjy6to9wV rO/5ZmIwh9WZkd5V1CCxttsON9X62ACYbGss5NTM8KmSHwonj/bmCh1g2LxI5wwl9+jwmpxZiLUJ VK1LF10YD3GLgaAHumMASRJZukmj3O5A41Cl2ZOOe3i7kVv+SMCzbzvyWwGSJMG/Qm+HxiB1KD+Z roIN7Y+e0ym378tyxed6WbT/mgCCGSb/oxLFEqcG9V1QfJTZyK4Ro0pCqE+DrLNQ75HKVfddiP3B ImLq/Ia2MOI05uWXKoxYASZ7WL4noibV5J0Eh4oRpoatUmZt7oojhnnKrQdjwhw/Z0whRMAZX0Q3 B1TNHlbd/ZBohSyZf1Y3aSA7cjus9WiYkpevUcC0cMYUYEQVa9/H73VREoSq+HW+7/YbEhH73Hxb 8xLuUikVD+X/k4y4hBO1o9X66v3hmG8TGzhZfoW674gW389GSD6YL6NQtEFBYY5fiMfewMYb4v9H cat8VilqpYn9ZoRNa0A8nhuF8VdpIjKddjUon4tpV+KFH5rg2b+nJUBjt2iufDR4Y47jLpwz75rQ yBM7Mxg5/8hfdLQoZXC7y2mUGJXq8ab3mB8MwytmA/chwKoVXRaCXIGnUWUmaCOdpXjn3ammMHsq 4rcjYwsBBHGaMgjV+ofvl9do27GTl3vrRwYpaL5Rnxw7r79OejM4xnRNpjM9OZBNnohBlBJytriE wGofgd9KUCF7LXnUNq/VnM0FdVdVv6dq1xpvGH26V7rAJ8Aq9aVYRHjVOH8rcLPlDvHkxk+K63Hg jEb3Yknmk3aW1Oi0LzeRuEnKvYC5511HkJ0OTWW4kuUd0gHhH4/WDhBxS5mCJTqlMUD7PjGD3cV6 BSH8QRhyVdmkPdJTgn+Bxzb+emvAk5etISps4mZRboyR/AbjdibXJwtmkBUSW7YHnepeE1WrjARm cex+I3VPhpEs8mWy95pA1jSuqEnS+eXrnWgtHCkb8K/COKSY7e0LQtbowvWVpp7XRcNge3AMu4RG Cv7L8mAy7/scwQfNalr1jtvYEDH6cJ/uX304bizhgDjIm/yBVMM7JW27v2375tqXQZlUJVaR2HLF +aaTGVK6T/e7u34/AlWGmxmw6RiYYvAXaIILFkumyhUhb+9VxOBiPwTZIyneJ193rFpRIeaYx+fe WeyaMVpCDNq9rM+Resa4Lj6G6DVRyqHC6XNgVm28R5F69WKD/JNLbo3KHQLtJOj1mY6N3mXLjPMO VynMBhhXHm0Erd7eMDHd37in4V0Z9dpaVBilOU1tsPVObA05wm9/p6X2uFIP3DHpP09TzVIGas1h 9Noyu8GMpN5cqVu8alOeA6br3A57lEy+04ygf1imVQHi/+QHgkibV1UhVxGFByQIg1E1NIiYVLEr 0KrCzV/BlJwc0q6MHvs2OPkBGXeZ5YVL+/rPxk/idVtFVZRaKZAuwVWr4VwYi277d37r5EhXj7cr Y4s9XctoVuEnnaw9E88HE7c3x/aBipVQSZuoJm8JxBss+mOA02d7vKyrZmA2QqvikO379IGjspC2 p+EHTwh2r3WOzg0tQLUDgAVQHMANkEXx5kH9XK9HvWNw3J5FZEXbT+QUToIeNCAxz1X+NOL92ID/ 0gxtCL8morm5TYwZ3RiAa3gOmwDr8jaoma36MhwHf90cJ8Ff5uK4O9V2WY4x+x7a52DcAuo8mowe uPi1omaxTz7JWOUXTIK4b/Q7dC68SnSvEu/JqeCk2Rhj0IttCtnjDr50yHGUF3nPTmmMckQTF5OG 6t/KWwx0ACR3pSDCkABRgYlNO1qZ/3Oy9v9qih1khR50GRgShO9dp9/xR9LCK+lZqbutaSeHmtxZ +hecXqrX596Whr4b5RwGdwHPZTDNxJGjz4oLc4VE9SaCbkumaTOh1sVzrEn3R4r/HPsS4rjLKwMJ D65y+W7OY08l9iY6oiyf4tIKS218OpQr8mO+ysWQKwmGTfuazlksfVTEZiXpmQ2kEE4ZP3Vcr5pW XF2e390WrhbfuFW9ttUMCAfY0F8E93YH/cxXq3SlVYPzK/LQp12DyseZ2gO19gTWRxb5TV/Y1Jfx KlONc8wmSaPvbmuIyj5XTeJW1DiSMKKdC9Njd9/ajk9L2/qo8cb9eMStwUIm8OsMXT06MNuWumYR kxdgl1s8j0Al+twS1QikGK3+li5v4f7NYkWSuGPr0Mwd5a3+vC79ZVBoJhTiTxZOPOd+meEQBi4a iAMb+fymnMpNCSUq23GSDw1oHVkUdS3GIEy/sjwKKkosoO5UJnDUe36bmUMLAvkwvvX70YUZqXL4 TKMxfK3jFAAwcKbzGTjBNP1+/gwFfvedk6NUEAQljyQ1JGfnEJ+USjO25bQCwRlRNG9d6ECpUuuQ S9yvYhSWyZn70RYmh6Xoj9HEL873ZTnYVv7fCZk2MuTXHx4raneERx8u2TKB4sdrkdofEPwdnGV/ PMAF/qzQaNCjPP4YVhu6Toud0oZUxNyf3VnHrrupt0GD8F5vkaTxRdofHP2wv1qQqOQkSq8MU+xU eSkdHzVMYS5QEucToeiEBk8WlbdV1Q/bvedaN6Boi2E3vnm6BTiisZSp/n3Z7wJFJZeB9ntQzPbD aRIBeSdflDS3l5b/Uh/OcBGC8JtylC2cDtifIFbww+j3oq9u7sjwJOKnxQ4beulII8kROoZcxzIL HgEgpAZ0DNMw0ZL++7K9OP1gXOiKNq9eP1+iaoEIocgemMStP7HZ66PnhJoglXxSeDajpdMbOK8r RUe46i9LQFEHX4p9md7DXd16CW+dC2LkB1QMaGEefK6QLdC/O/YqDdUZfvQHf2HKSI5ppzreRFi4 ZHINNTEB7mzr+MOIjVQ+RDwPR3xtPt/kZG5SsNM9+Q5/EsxUJswkhWrS5sJ/ZfofeRzu/ul+T4Zr trBZVCO+S25tB8TixBaW8YPWN8ceIHcTkAfT0zG1Qlwt6AAUAKO0iqGjDfxEulAh7QysF7oxOPAq 29tH4+F0OX+5BIfzen5gS3zYKiXG8sb4Z65ehtBZZl0PNR9qRH08MGLlu4drvfLBYo+8WPlcBS1X uOpioKtsLcvke9WhGpr/oVIGHH5rLa1m4ypknIUek4zaYVCLz2J5ZfiGOJYPHSMZFmBHbeKgIYpB j5dqnXv6HAJET+UdAj4RRMaHe1MW4Yr5zm3now6z8bW1n2z9MYPZbEnF2hJtwYYyfuwUDVm8CXm5 dkLnABvgz5Pyp3zO4EzrXhX0Y7bqOdsztjEJ0oizK77w77I7RZ8hx8WXoA5CCMO3K7fUwnZz0jMf 5D8o/8yHxEuAdnUcjZ94sK2MoFZGW0ExVRCGCKAnN/k0BQZWeQHB5a51t6todaajsc7/Nwem1yxZ vOc6n2vY+zB2ujoNMF4Wn29Mfk8dgzweXBM8tdcL7F1Vyp0AmjcDLt9/V+0nRTP7o84x3UU6KpG6 cxj/lKWQtG5sfR5J4aTo10goVMgmNU4uAPM0wTZ23iXtMAJ1lwoKFbVnW9dHdW76I81hW9FVQcTH VA+4hULj3iEO6eI7Jc92nRR4QniVwFnuvIJa8WoaDYE+whr1XkL6XVq1UUTd2fJA5qiPBrPvluTi dwTgjunUU81nPEUxOmitG+03iFXexepU5cgKZlbdVfufeHe35txDjye28tWJO5ek4BCwN72KDvtt bE5CiXpun8wICUsV0AEMRNhxI0esposyuOzQ155IBW7Wk/Fejh9o02y4hz8X2fhu2uA75xB/PfL8 ZdHSo465tj24UBKbVSvzsHYzqN0/QdIDLRm6UFZoo0gO3jXpM3bdLucTPggUcOuxmjmVsJHOFLln IdhQS7RD5Z/QbjjpBGlch08SJyhH+WMgLIflghmE+zHoVAvtFK6ggv+g99rRgRV/RSm7DjYShqPs ZVtaMelDU5+yKNf8lgcINV84SxA9dYraUr4u3dsNCMJUWE4j+F/U0Zjg1IFjK/6AnxcdFFwwZDx0 hL9k0iVA8Me6+gtULYTPreKLeu2H97qdt+viPR5Nke+c8+zZQbPo7xR9cT9JpesZ2g+fOeQt6H7k gGPAmcduuDNcuX9dUTRnMyDw8H3zmwsKXC49CR+95c3uXUrjoOHY0hXjH4Qo5HFZP1BLT+5xaj15 FXJ0xxr9+F3j6NmHfz9dI5nvdDLuX+RWY8svpyepaa5PcdMrcGKpmXOWj8CDPGjmHlFam7BdaSPM wSOLCr2TycgQ5AYYt+0PVET/qjlSo1TRSXRZjulRZh0/qjdbcktAhr2T8C/zkidl1Qc7D/b44dzw L2mtrL4CyNwQ+D5B55QNcqrBVQP2A4vPnzehINoDxVOYlsPfuRHevlk5bNTL+AkecbgKcjhBEmUQ r/5f61QWVqcVuy3hjrZRvyCOxt33zKfXzULGBPKGql1gCbAQYe0GW+MXglZR2KPZOsDQV9qTBEhn K/bpYYf7+Qtoy/rO/u/QHcAEcxURLuOl7DUTL9emP5+fCXEbdvlVSkwNZFG3mzEhf66djpim2Ug3 r4Fe5MI6UFLUOuoO6UhPn0X+oV/a6EJs+BATiNAeRjp/8Qowv1EGle46D7l3u2HpWrpfy7orrGqw IBAvOVXppug56lR4dTkGNj6690GSAmGx2w0lOAM3uprvCu3NYKdLK/vpMKCv2WBuA/o6sHGM/ySE G/O4LYETtnoYQpErnmWpiHI3L+FQGbz896fBossUvYn+U3jfn8q8ycRDntvwXKuh7V8La5rp3o+/ Uwygi6617NoaRU9AA61kDGDpeLLtDA/Ca5oWfFEjKS19zIxvaWrWHSTyqovYJCoViQjrE4/5Sr5j OI/tZKVkHDw8VlD60/HugIaaLCkPVCCfEeC+4rnvlu2GWbmlpAdOXxewsz1z37k3GTGbWR7cs7PF W7KRqqfDaBd1fK8JtQdp29C0gmAM5S8ngwizvxYiFKnV9MfhOY4FsXWek44a7xPVlDlJXOFAmDnt 0mgifE71mWB285H/wPJjKJsA55tbj5Sk/Sb9PQIiBWK2ivH1zDglgk6VC6PtdanmscVzLgBnyaJ8 I9Hqm35Fca3DB0GYYLFQ5MYFsJyau1OCMVNBeyzMoq6PjyyMVRUiKryO60sdWH6vuVlg8Bvt/N1c PZCWSzWq/V84W8h6zu3mBBMI6u7GP8jTanjORZUYgb481qlN4/ZwSMCD0dd1MZrYifmFJ+hd3Mhq vcIh56cVgjOXB87bxOZNGtTvN8yyD9da/mtJ+YX7xwxzd5IyLXDJeCKFfOlVg7QBaYwN2FSMSk+T tubp15WmBiwiMVSQP84y75rshaMrnpcXuIZUEaukWM0GcwXPCou3BValgiYK9qPe2Hjrx8emJmvL 01xa8+dugJXokDkRIfNok9W3uV1gnfKFbCSgiVbB7YGrT0r2WnFFSEl8OtY75u6j9nStKBx9NrgI OC8DViSu+CKN/DWCdIAsZBWqy9YYIIkgWAE3v/qDv+BzbBHl0R9lCFHE/veUGx/bNLMnEQf4ULqx at3gOUJxt010JbKqes9Qj4tppFKEGHPPW2oxB/HPvTkSXNxL7LZ6gaZvgSh+BG5iBXa+WKe0MSKH 2dVPyp0l+SnZLgVgfro8mCVdQZ3T6+0f8j/NPuyG79BGvSBf/pJBi+KNVczY+g0G5hAbN98YoWkB k552nRWSCwwKE2GLv+xvo9YelEFEZ4nZAXj4DL7rbsbSWLv7mhL6BXwAJ32U8n0eispHje1O02Yi nNY61SHZTRmNi1Cj5l1OUShCIGellCdTIvU1LyqGwaEQjw+MlUamZqL6s7DHWdzBKzhBOg4XM06I TSjEOQ6wcUaWbSTNGvIaU8HFntiAZ/WvAQukxcgpVvLvdMnTXdAyitSbJ7T/6jRBG6Gwl6ApstYR E9NaTjmhFteaBBCBMBgMMnvuHHOlMJmKBPglbtA0S5rm93+4ddM/woC6CkwDQdngF8HCUiuNlDFN HPaTtM7SSZBfk3M2PBgFngUu3Cd6FpfEdd7nyXNM0G11uZIIDwFM0/8TJIiSg28z1VeJnAhCpRFh yYqrfQJ6VIjryUzdggZAMA+eNrg0SE4rav4Rli7tFoioBpJI6jKc8plp0VbyrQzfAIxuHNlDKyfs W9aeXqe6pNkOtSgWw5SEnsTfS625d2NulVJE7jivxCBam7MyGV/c7GbhxMbe+ZY6/EmuuUvcbIrE U/f7HMK+kTHo4ncSugiGed0alBOqUs7K+hrERJ3awQt8J9pcY2Q758ennniuSES1CrtzbzorSzEj FHprjeIDVlHOis1XDzgWb4R2a+ZFH7oEoF16lw+Z9wZCN9besEPpUMLoaiTiKA1iJbGMGySjl2UR nxY/Tmala3bfDqICu/QS1ztQAdFAMHzvczvfLj0c9OtZ9EL54kACWQvYzIJltmppv/HxgN6E+Sem xz0r/M6zLGDINgelh8UvSKWAQDpiVKyqxYQ+sSmHR5aRONitcp2WfL4Wk5Sce+NptOP2FMQozY4Z C0B6aPX1I89iqAgfzlKCLwxgEnKTwnd1nEHSEHlKYcZieIx4noB1lZf1pxzcSIPzuVYj2C+wTWZ4 uX0QYY3yzm2eOm5upDX2l+h7705WVd9zZYgt0AOvLICf5+130lTOgm3PHgpxE89S38vwZ5EbKQYw uCBuLiybcVGhDbMMowjyyi0mQM2CALum2AeWG6kn2mxBAl35uMcZ0NakvNtp1aUAGW2FvawIoJXT 8ePpHSAjS5ClFt7OGI6B8j1yuF33dcC+Ldz/ruoVhlEfTno8uorxPB/GQq497lVuOLFNEsaw4CZl 0gCoouPMlOCld2XR638vke9t9G6ywBQ1chhYJLdW/z9J8eQozdeHYa3mjbJzUEuG8XFLhXrahKYg LgHdl10gsPHEBTFBeQBt5Qkr3zfxAVwkerK6h9wVi26L0Ga/43xplat1DwhffLWebLP1AxEh9EOa afubMy9KfosCQZpklg6bbr5PKMR18mp9Qg2eg93fgZObC2yF2tb9CU8GA3MrsoWcHqhSpOCjJ1+P qNNI/vSNblCRiAXdKLNwKuIbVRukGYn/vdAAb0jrfoOjFBSTcmXXKPLtuCxJjmr1MXJZkoUdI5ER 7cmvg/Zw7+/RKVHtMa46srgTzQ/x2hIraUi7EmpMPXiF56HZeZfun1pkVkPNRkfQaatHZcTf5qou AbqZLkbxf9/yxYv3irjdCMuDTB3Z4fnX83lyn83iamiVPityldgU26pzpzAtGH/NL2QUZsgB6O2I ewMyr30tqWp+uAaTN6HCXSR5vlo3ERVsNNXL3tHc3b4zLQd/kKiTFWk+ReuBvmcjAHccIZ+QC9Kc aM9lqpJ6/fTCt/AwfK9enD4yrklAAOtI/2Lh86+YXu0/ypeS59rdCQPcHjvTmk6+mT5+rZss1oax C1NGOza3p412oubohngyxgN8F7KMjlDj0toqBQoRdlzlGqQKT9IR7nSP4M0fx4ScXIVAgn637lnl 4YcDeRxz5TGmuxUA28SUFjwvGK/sqoq/4QR6mMRycOAgHLhZw9ZZqjlhvT6A6GuShezDKdV/71B5 1O6NqZg4vPKqrzYo2sKmF9DhTRnoV8RdlB6EKurkgufwttX64/aS5Y0h2j6fh8dM0V7Qoo3UqQhq haiRWYh97FuZbEGC0ciBtdX7AzNKShAZrOqtFiLbiLEDkXmccQWWbN829A8N40zcRRa7I0jpFGBQ fbTZaqFK4HT/RxmCfm0jbe6Ais9DD7mwdILH0GCPVAIoeeI/BU84abMlk4mgyUFl5++7+pRtr3Nr 5XwGJzhID1kXRzCZELnofxaX6tjBHZTPtK3bvqp1uLVB4VwCnzFDlz11wS79CCqU1Ezrdv5d67Cz ey7vGuO21rL51mpd5XZYwG6cQhPNOmCPOfFQSjzn+sTd9yyq7KGkvMk4XdKYFgvOEQVqifs6mDGZ gZlYvPle7+dkZcFni5DI3A8hAaGegrJ5aN/s4UygN4vte9I7LM6iSG4Q9HzXg1+uZ9AwDx62pbXC ERAEH8QoELqXy5Z7i+w9NyPo/z4kH16pbeWPPVoNJhQRWeE9V0I+OXpg5PHZDDDhatGYJIh7CPME SY140KYacef5NSgvCozVnKAmn/03wJF+V7ilq+uTCbWh0AWl0Ofd9HrBzptl67u1rEtL1SezoKu7 A0U= `protect end_protected
---------------------------------------------------------------------------------------------------- -- serial_multiplier.vhd --- ---------------------------------------------------------------------------------------------------- -- Author : Miguel Morales-Sandoval --- -- Project : "Hardware Arquitecture for ECC and Lossless Data Compression --- -- Organization : INAOE, Computer Science Department --- -- Date : July, 2004. --- ---------------------------------------------------------------------------------------------------- -- Serial multiplier for F_2^m ---------------------------------------------------------------------------------------------------- -- Coments: The input buses need to have valid data when Reset signal is asserted ---------------------------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; -------------------------------------------------------- entity serial_multiplier_233 is generic ( NUM_BITS : positive := 233 -- The order of the finite field ); port( ax : in std_logic_vector(NUM_BITS-1 downto 0); bx : in std_logic_vector(NUM_BITS-1 downto 0); cx : out std_logic_vector(NUM_BITS-1 downto 0); -- cx = ax*bx mod Fx reset : in std_logic; clk : in std_logic; done : out std_logic ); end serial_multiplier_233; ----------------------------------------------------------- architecture behave of serial_multiplier_233 is ----------------------------------------------------------- -- m = 233 x233 + x74 + 1 constant Fx: std_logic_vector(NUM_BITS-1 downto 0) := "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000001"; ----------------------------------------------------------- signal Op1 : std_logic_vector(NUM_BITS-1 downto 0); -- Multiplexers for ax and cx depending upon b_i and c_m signal Op2 : std_logic_vector(NUM_BITS-1 downto 0); signal bx_shift : std_logic_vector(NUM_BITS-1 downto 0); -- B and C shifted one position to the rigth signal cx_shift : std_logic_vector(NUM_BITS-1 downto 0); signal bx_int : std_logic_vector(NUM_BITS-1 downto 0); -- Internal registers signal cx_int : std_logic_vector(NUM_BITS-1 downto 0); -- Internal registers signal counter: std_logic_vector(7 downto 0); -- 8-bit counter, controling the number of iterations: m ----------------------------------------------------------- -- States for the finite state machine ----------------------------------------------------------- type CurrentState_type is (END_STATE, MUL_STATE); signal CurrentState: CurrentState_type; ----------------------------------------------------------- begin ----------------------------------------------------------- cx <= cx_int; -- Result of the multiplication Bx_shift <= bx_int(NUM_BITS-2 downto 0)& '0'; -- Shift Bx and Cx to left one position Cx_shift <= cx_int(NUM_BITS-2 downto 0)& '0'; -- Multiplexer to determine what value is added to C_x in each iteration Op1 <= ax when bx_int(NUM_BITS-1) = '1' else -- The selector for these multiplexors are the most significant bits of B_x and C_x (others => '0'); Op2 <= Fx when cx_int(NUM_BITS-1) = '1' else (others => '0'); ------------------------------------------------------------ -- The finite state machine, it takes m cycles to compute -- the multiplication, a counter is used to keep this count ------------------------------------------------------------ FSM_MUL: process (CLK) Begin if CLK'event and CLK = '1' then if Reset = '1' then counter <= "11101000"; -- m-1 value, in this case, it is 162, be sure to set the correct value bx_int <= bx; cx_int <= (others => '0'); Done <= '0'; CurrentState <= MUL_STATE; else case CurrentState is when MUL_STATE => -- processes a bit of bx Cx_int <= cx_shift xor Op1 xor Op2; counter <= counter - 1; if counter = "00000000" then -- The done signal is asserted at the same time that the result is computed. CurrentState <= END_STATE; Done <= '1'; else bx_int <= bx_shift; end if; when END_STATE => CurrentState <= END_STATE; Done <= '0'; when others => null; end case; end if; end if; end process; end behave;
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity compar is port ( a : in std_logic_vector(3 downto 0); b : in std_logic_vector(3 downto 0); so_a : out std_logic; so_b : out std_logic ); end entity; architecture behav of compar is signal a_b, b_b,a_b1, b_b1,a_b2, b_b2,a_b3, b_b3, a_b4, b_b4: std_logic; begin a_b<='0'; b_b<='0'; a_b1<=(a(0) and (not b(0))) or (a_b and a(0)) or ((a_b and (not (b(0))))); b_b1<=((not a(0)) and b(0)) or ((not a(0)) and b_b) or (b(0) and b_b); a_b2<=(a(1) and (not b(1))) or (a_b1 and a(1)) or ((a_b1 and (not (b(1))))); b_b2<=((not a(1)) and b(1)) or ((not a(1)) and b_b1) or (b(1) and b_b1); a_b3<=(a(2) and (not b(2))) or (a_b2 and a(2)) or ((a_b2 and (not (b(1))))); b_b3<=((not a(2)) and b(2)) or ((not a(2)) and b_b2) or (b(2) and b_b2); a_b4<=(a(3) and (not b(3))) or (a_b3 and a(3)) or ((a_b3 and (not (b(3))))); b_b4<=((not a(3)) and b(3)) or ((not a(3)) and b_b3) or (b(3) and b_b3); so_a <= a_b4; so_b <= b_b4; end architecture;
---------------------------------------------------------------------------------------------------- -- inverter_maia.vhd --- ---------------------------------------------------------------------------------------------------- -- Inverter for F_2^m ---------------------------------------------------------------------------------------------------- -- Author : Miguel Morales-Sandoval --- -- Project : "Hardware Arquitecture for ECC and Lossless Data Compression --- -- Organization : INAOE, Computer Science Department --- -- Date : July, 2004. --- ---------------------------------------------------------------------------------------------------- -- Coments: This is an implementation of the Modified Almost Inverse Algorithm. -- The input buses need to have valid data when Reset signal is asserted. -- All internal registers and operations are performed one bit more than the input ---------------------------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_unsigned.all; use IEEE.STD_LOGIC_arith.all; -------------------------------------------------------- entity inverter_maia is generic( NUM_BITS : positive := 163 -- The order of the finite field ); port( ax : in STD_LOGIC_VECTOR(NUM_BITS-1 downto 0); -- input polynomial of grade m-1 Fx : in STD_LOGIC_VECTOR(NUM_BITS downto 0); -- prime polynomial of grade m clk : in STD_LOGIC; rst : in STD_LOGIC; done : out STD_LOGIC; z : out STD_LOGIC_VECTOR(NUM_BITS-1 downto 0) ); end inverter_maia; --------------------------------------------------------- architecture behave of inverter_maia is --------------------------------------------------------- signal B,C,U,V : STD_LOGIC_VECTOR(NUM_BITS downto 0); -- Internal processing registers, one bit more signal Bx_Op1 : STD_LOGIC_VECTOR(NUM_BITS downto 0); -- Multiplexer which depends on if B is ever or odd signal Ux_div_x : STD_LOGIC_VECTOR(NUM_BITS downto 0); -- U and B divided by x signal Bx_div_x : STD_LOGIC_VECTOR(NUM_BITS downto 0); constant UNO : STD_LOGIC_VECTOR(NUM_BITS downto 0) := "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"; signal grade_u : std_logic_vector(7 downto 0); -- Return the grade of U and V, it is assumed they are less than 256 signal grade_v : std_logic_vector(7 downto 0); signal done_gu, done_gv, rst_grade: std_logic; ---------------------------------------------------------------------------------- -- States fot the FSM controlling the execution of the algorithm ---------------------------------------------------------------------------------- type CurrentState_type is (END_STATE, WAIT_GRADE, LOOP_U0, CALC_GRADE, NEXT_STEP); signal State: CurrentState_type; ---------------------------------------------------------------------------------- begin ------------------------------------------------------ Ux_div_x <= '0' & U(NUM_BITS downto 1); -- Dividing U and B by x Bx_div_x <= '0' & Bx_Op1(NUM_BITS downto 1); ------------------------------------------------------ Bx_Op1 <= B xor Fx when B(0) = '1' else -- Multiplexer for operand B B; ------------------------------------------------------ -- Two instances for computing the grade of U and V ------------------------------------------------------ gradeU: entity work.grade(grade) port map (rst_grade, clk, U, done_gu, grade_u); gradeV: entity work.grade(grade) port map (rst_grade, clk, V, done_gv, grade_v); ------------------------------------------------------- -- The Modified ALmost Inverse Algorithm implementation ------------------------------------------------------- EEAL: process (clk) begin -- syncronous reset if CLK'event and CLK = '1' then if (rst = '1')then -- initialize internal registers State <= LOOP_U0; B <= UNO; U <= '0'&Ax; V <= Fx; C <= (others => '0'); z <= (others => '0'); -- set to zero the output register Done <= '0'; rst_grade <= '0'; else case State is ----------------------------------------------------------------------------------- when LOOP_U0 => -- Stay here while U be even if U(0) = '1' then if U = UNO then -- The algorithm finishes when U = 1 Z <= B(NUM_BITS-1 downto 0); Done <= '1'; State <= END_STATE; else -- Compute the grade of the the currents values of U and V rst_grade <= '1'; State <= CALC_GRADE; end if; else -- Divide U and B and repeat the process U <= Ux_div_x; B <= Bx_div_x; end if; ----------------------------------------------------------------------------------- when CALC_GRADE => -- generate the reset signal and wait for the result rst_grade <= '0'; state <= WAIT_GRADE; ----------------------------------------------------------------------------------- when WAIT_GRADE => if done_gu = '1' and done_gv = '1' then if(grade_u < grade_v) then -- Interchange the registers U <-> V and B <-> C U <= V; V <= U; B <= C; C <= B; end if; State <= NEXT_STEP; -- wait a cycle to compute with the current values assigned end if; ----------------------------------------------------------------------------------- when NEXT_STEP => -- update U and B with the values previously assigned U <= U xor V; B <= B xor C; State <= LOOP_U0; ----------------------------------------------------------------------------------- when END_STATE => -- Do nothing State <= END_STATE; ----------------------------------------------------------------------------------- when others => null; end case; end if; end if; end process; end behave;
-- ----------------------------------------------------------------------- -- -- Syntiac VHDL support files. -- -- ----------------------------------------------------------------------- -- Copyright 2005-2009 by Peter Wendrich ([email protected]) -- http://www.syntiac.com -- -- This source file is free software: you can redistribute it and/or modify -- it under the terms of the GNU Lesser General Public License as published -- by the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This source file is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see <http://www.gnu.org/licenses/>. -- -- ----------------------------------------------------------------------- -- -- PS/2 mouse driver -- -- Uses: io_ps2_com -- -- ----------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.numeric_std.ALL; -- ----------------------------------------------------------------------- entity io_ps2_mouse is generic ( -- Enable support for intelli-mouse mode. -- This allows the use of the scroll-wheel on mice that have them. intelliMouseSupport : boolean := true; -- Number of system-cycles used for PS/2 clock filtering clockFilter : integer := 15; -- Timer calibration ticksPerUsec : integer := 33 -- 33 Mhz clock ); port ( clk: in std_logic; reset : in std_logic := '0'; ps2_clk_in: in std_logic; ps2_dat_in: in std_logic; ps2_clk_out: out std_logic; ps2_dat_out: out std_logic; mousePresent : out std_logic; trigger : out std_logic; leftButton : out std_logic; middleButton : out std_logic; rightButton : out std_logic; deltaX : out signed(8 downto 0); deltaY : out signed(8 downto 0); deltaZ : out signed(3 downto 0) ); end entity; -- ----------------------------------------------------------------------- architecture rtl of io_ps2_mouse is constant ticksPer100Usec : integer := ticksPerUsec * 100; constant tickTimeout : integer := ticksPerUsec * 3500000; type mainStateDef is ( stateInit, stateInitAA, stateInitID, stateReset, stateReset2, stateResetAck, intelliKnock, intelliKnockAck, intelliCheckId, stateSetDataReporting, stateSetDataReportingAck, stateWaitByte1, stateWaitByte2, stateWaitByte3, stateWaitByte4); signal masterState : mainStateDef := stateInit; signal timeoutCount : integer range 0 to tickTimeout := 0; signal resetCom : std_logic; signal inIdle : std_logic; signal recvTrigger : std_logic := '0'; signal sendTrigger : std_logic := '0'; signal sendBusy : std_logic; signal sendByte : unsigned(7 downto 0); signal recvByte : unsigned(10 downto 0); signal intelliMouse : std_logic := '0'; signal intelliCnt : unsigned(2 downto 0) := "000"; begin myPs2Com : entity work.io_ps2_com generic map ( clockFilter => clockFilter, ticksPerUsec => ticksPerUsec ) port map ( clk => clk, reset => resetCom, ps2_clk_in => ps2_clk_in, ps2_dat_in => ps2_dat_in, ps2_clk_out => ps2_clk_out, ps2_dat_out => ps2_dat_out, inIdle => inIdle, sendTrigger => sendTrigger, sendByte => sendByte, sendBusy => sendBusy, recvTrigger => recvTrigger, recvByte => recvByte ); -- -- Mouse state machine process(clk) begin if rising_edge(clk) then resetCom <= '0'; mousePresent <= '0'; trigger <= '0'; sendTrigger <= '0'; if timeoutCount /= 0 then timeoutCount <= timeoutCount - 1; else masterState <= stateReset; end if; case masterState is -- -- Reset sequence states -- when stateReset => resetCom <= '1'; timeoutCount <= tickTimeout; masterState <= stateReset2; when stateReset2 => -- Reset mouse if sendBusy = '0' then sendByte <= X"FF"; sendTrigger <= '1'; masterState <= stateResetAck; end if; when stateResetAck => if recvTrigger = '1' then masterState <= stateInit; end if; -- -- Mouse BAT handling states (Basic assurance test) -- when stateInit => -- Wait for mouse to perform self-test timeoutCount <= tickTimeout; masterState <= stateInitAA; when stateInitAA => -- Receive selftest result. It should be AAh. if recvTrigger = '1' then if recvByte(8 downto 1) = X"AA" then masterState <= stateInitID; end if; end if; when stateInitID => -- Receive device ID (it isn't checked) if recvTrigger = '1' then timeoutCount <= tickTimeout; masterState <= stateSetDataReporting; intelliCnt <= (others => '0'); if intelliMouseSupport then masterState <= intelliKnock; end if; end if; -- -- Intelli Mouse knock sequence for wheel support -- when intelliKnock => if sendBusy = '0' then sendTrigger <= '1'; masterState <= intelliKnockAck; intelliCnt <= intelliCnt + 1; case intelliCnt is when "000" => sendByte <= X"F3"; -- Set sample rate when "001" => sendByte <= X"C8"; -- Rate 200 when "010" => sendByte <= X"F3"; -- Set sample rate when "011" => sendByte <= X"64"; -- Rate 100 when "100" => sendByte <= X"F3"; -- Set sample rate when "101" => sendByte <= X"50"; -- Rate 80 when "110" => sendByte <= X"F2"; -- Request ID when others => sendByte <= (others => '-'); end case; end if; when intelliKnockAck => if recvTrigger = '1' then masterState <= intelliKnock; -- End of knock sequence, check the mouse ID if intelliCnt = "111" then masterState <= intelliCheckId; end if; end if; when intelliCheckId => if recvTrigger = '1' then masterState <= stateSetDataReporting; intelliMouse <= '0'; if recvByte(8 downto 1) = X"03" then intelliMouse <= '1'; end if; end if; -- -- Enable data reporting -- when stateSetDataReporting => if sendBusy = '0' then sendByte <= X"F4"; sendTrigger <= '1'; masterState <= stateSetDataReportingAck; end if; when stateSetDataReportingAck => if recvTrigger = '1' then masterState <= stateWaitByte1; end if; -- -- Receive movement packet -- when stateWaitByte1 => mousePresent <= '1'; if inIdle = '1' then timeoutCount <= tickTimeout; end if; if recvTrigger = '1' then leftButton <= recvByte(1); rightButton <= recvByte(2); middleButton <= recvByte(3); deltaX(8) <= recvByte(5); deltaY(8) <= recvByte(6); masterState <= stateWaitByte2; end if; when stateWaitByte2 => mousePresent <= '1'; if recvTrigger = '1' then deltaX(7 downto 0) <= signed(recvByte(8 downto 1)); masterState <= stateWaitByte3; end if; when stateWaitByte3 => mousePresent <= '1'; if recvTrigger = '1' then deltaY(7 downto 0) <= signed(recvByte(8 downto 1)); if intelliMouse = '1' then masterState <= stateWaitByte4; else deltaZ <= (others => '0'); trigger <= '1'; masterState <= stateWaitByte1; end if; end if; when stateWaitByte4 => mousePresent <= '1'; if recvTrigger = '1' then deltaZ <= signed(recvByte(4 downto 1)); trigger <= '1'; masterState <= stateWaitByte1; end if; end case; if reset = '1' then masterState <= stateReset; end if; end if; end process; end architecture;
library IEEE; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use ieee.std_logic_unsigned.all; entity BRESENHAMER is port ( WRITEENABLE : out std_logic; X : out std_logic_vector(9 downto 0); Y : out std_logic_vector(8 downto 0); X1 : in std_logic_vector(9 downto 0); Y1 : in std_logic_vector(8 downto 0); X2 : in std_logic_vector(9 downto 0); Y2 : in std_logic_vector(8 downto 0); SS : out std_logic_vector(3 downto 0); CLK : in std_logic; STARTDRAW : in std_logic; DBG : out std_logic_vector(11 downto 0); RESET : in std_logic ); end entity BRESENHAMER; architecture BEHAVIORAL of BRESENHAMER is signal myx1, myx2 : std_logic_vector(11 downto 0); signal myy1, myy2 : std_logic_vector(11 downto 0); signal p : std_logic_vector(11 downto 0); signal p0_1 : std_logic_vector(11 downto 0); signal p0_2 : std_logic_vector(11 downto 0); signal p0_3 : std_logic_vector(11 downto 0); signal p0_4 : std_logic_vector(11 downto 0); signal p0_5 : std_logic_vector(11 downto 0); signal p0_6 : std_logic_vector(11 downto 0); signal p0_7 : std_logic_vector(11 downto 0); signal p0_8 : std_logic_vector(11 downto 0); signal p_1 : std_logic_vector(11 downto 0); signal p_2 : std_logic_vector(11 downto 0); signal p_3 : std_logic_vector(11 downto 0); signal p_4 : std_logic_vector(11 downto 0); signal p_5 : std_logic_vector(11 downto 0); signal p_6 : std_logic_vector(11 downto 0); signal p_7 : std_logic_vector(11 downto 0); signal p_8 : std_logic_vector(11 downto 0); signal ndx, ndy : std_logic_vector(11 downto 0); signal dx : std_logic_vector(11 downto 0); signal dy : std_logic_vector(11 downto 0); signal t_2dx : std_logic_vector(11 downto 0); signal t_2dy : std_logic_vector(11 downto 0); signal neg_dx : std_logic_vector(11 downto 0); signal neg_dy : std_logic_vector(11 downto 0); signal t_2neg_dx : std_logic_vector(11 downto 0); signal t_2neg_dy : std_logic_vector(11 downto 0); signal dx_minus_dy : std_logic_vector(11 downto 0); signal minus_dx_minus_dy : std_logic_vector(11 downto 0); signal minus_dx_plus_dy : std_logic_vector(11 downto 0); signal dx_plus_dy : std_logic_vector(11 downto 0); signal state : std_logic_vector(3 downto 0) := "0000"; signal condx1x2, condy1y2 : std_logic; signal ccounter : std_logic_vector(18 downto 0) := "0000000000000000000"; constant idle : std_logic_vector(3 downto 0) := "0000"; constant init : std_logic_vector(3 downto 0) := "0001"; constant case1 : std_logic_vector(3 downto 0) := "0010"; constant case2 : std_logic_vector(3 downto 0) := "0011"; constant case3 : std_logic_vector(3 downto 0) := "0100"; constant case4 : std_logic_vector(3 downto 0) := "0101"; constant case5 : std_logic_vector(3 downto 0) := "0110"; constant case6 : std_logic_vector(3 downto 0) := "0111"; constant case7 : std_logic_vector(3 downto 0) := "1000"; constant case8 : std_logic_vector(3 downto 0) := "1001"; constant clear : std_logic_vector(3 downto 0) := "1010"; begin ndx <= ("00" & X2) - ("00" & X1); ndy <= ("000" & Y2) - ("000" & Y1); neg_dx <= 0 - dx; neg_dy <= 0 - dy; DBG <= p; dx_minus_dy <= dx + neg_dy; minus_dx_minus_dy <= neg_dx + neg_dy; minus_dx_plus_dy <= neg_dx + dy; dx_plus_dy <= dx + dy; t_2dy <= dy(10 downto 0) & '0'; t_2dx <= dx(10 downto 0) & '0'; t_2neg_dy <= neg_dy(10 downto 0) & '0'; t_2neg_dx <= neg_dx(10 downto 0) & '0'; p0_1 <= t_2dy + neg_dx; p0_2 <= t_2dx + neg_dy; p0_3 <= t_2neg_dx + dy; p0_4 <= t_2dy + neg_dx; p0_5 <= t_2neg_dy + dx; p0_6 <= t_2neg_dx + dy; p0_7 <= t_2dx + neg_dy; p0_8 <= t_2neg_dy + dx; p_1 <= p + t_2dy when p(11)='1' else p + t_2dy + t_2neg_dx; p_2 <= p + t_2dx when p(11)='1' else p + t_2dx + t_2neg_dy; p_3 <= p + t_2neg_dx when p(11)='1' else p + t_2neg_dx + t_2neg_dy; p_4 <= p + t_2dy when p(11)='1' else p + t_2dy + t_2dx; p_5 <= p + t_2neg_dy when p(11)='1' else p + t_2neg_dy + t_2dx; p_6 <= p + t_2neg_dx when p(11)='1' else p + t_2neg_dx + t_2dy; p_7 <= p + t_2dx when p(11)='1' else p + t_2dx + t_2dy; p_8 <= p + t_2neg_dy when p(11)='1' else p + t_2neg_dy + t_2neg_dx; X <= ccounter(9 downto 0) when state = clear else myx1(9 downto 0); Y <= ccounter(18 downto 10) when state = clear else myy1(8 downto 0); SS <= state; WRITEENABLE <= '0' when state = idle or state = init else '1'; process (CLK) is begin if (rising_edge(CLK)) then if (state = idle) then if (RESET = '1') then state <= clear; ccounter <= (others => '0'); elsif (STARTDRAW = '1') then myx1(9 downto 0) <= X1; myx1(11 downto 10) <= "00"; myy1(8 downto 0) <= Y1; myy1(11 downto 9) <= "000"; myx2(9 downto 0) <= X2; myx2(11 downto 10) <= "00"; myy2(8 downto 0) <= Y2; myy2(11 downto 9) <= "000"; dx <= ndx; dy <= ndy; state <= init; end if; elsif (state = init) then if (dx(11) = '0' and dy(11) = '0' and dx_minus_dy(11) = '0') then state <= case1; p <= p0_1; elsif (dx(11) = '0' and dy(11) = '0' and dx_minus_dy(11) = '1') then state <= case2; p <= p0_2; elsif (dx(11) = '1' and dy(11) = '0' and minus_dx_minus_dy(11) = '1') then state <= case3; p <= p0_3; elsif (dx(11) = '1' and dy(11) = '0' and minus_dx_minus_dy(11) = '0') then state <= case4; p <= p0_4; elsif (dx(11) = '1' and dy(11) = '1' and minus_dx_plus_dy(11) = '0') then state <= case5; p <= p0_5; elsif (dx(11) = '1' and dy(11) = '1' and minus_dx_plus_dy(11) = '1') then state <= case6; p <= p0_6; elsif (dx(11) = '0' and dy(11) = '1' and dx_plus_dy(11) = '1') then state <= case7; p <= p0_7; else state <= case8; p <= p0_8; end if; elsif (state = case1) then if (myx1 = myx2) then state <= idle; else myx1 <= myx1 + 1; p <= p_1; if (p(11) = '0') then myy1 <= myy1 + 1; end if; end if; elsif (state = case2) then if (myy1 = myy2) then state <= idle; else myy1 <= myy1 + 1; p <= p_2; if (p(11) = '0') then myx1 <= myx1 + 1; end if; end if; elsif (state = case3) then if (myy1 = myy2) then state <= idle; else myy1 <= myy1 + 1; p <= p_3; if (p(11) = '0') then myx1 <= myx1 - 1; end if; end if; elsif (state = case4) then if (myx1 = myx2) then state <= idle; else myx1 <= myx1 - 1; p <= p_4; if (p(11) = '0') then myy1 <= myy1 + 1; end if; end if; elsif (state = case5) then if (myx1 = myx2) then state <= idle; else myx1 <= myx1 - 1; p <= p_5; if (p(11) = '0') then myy1 <= myy1 - 1; end if; end if; elsif (state = case6) then if (myy1 = myy2) then state <= idle; else myy1 <= myy1 - 1; p <= p_6; if (p(11) = '0') then myx1 <= myx1 - 1; end if; end if; elsif (state = case7) then if (myy1 = myy2) then state <= idle; else myy1 <= myy1 - 1; p <= p_7; if (p(11) = '0') then myx1 <= myx1 + 1; end if; end if; elsif (state = case8) then if (myx1 = myx2) then state <= idle; else myx1 <= myx1 + 1; p <= p_8; if (p(11) = '0') then myy1 <= myy1 - 1; end if; end if; elsif (state = clear) then ccounter <= ccounter + 1; if (ccounter = "1111111111111111111") then state <= idle; end if; end if; end if; end process; end architecture BEHAVIORAL;
--------------------------------------------------------------------------------------------------- -- divider_f2m.vhd --- ---------------------------------------------------------------------------------------------------- -- Author : Miguel Morales-Sandoval --- -- Project : "Hardware Arquitecture for ECC and Lossless Data Compression --- -- Organization : INAOE, Computer Science Department --- -- Date : July, 2004. --- ---------------------------------------------------------------------------------------------------- -- Inverter for F_2^m ---------------------------------------------------------------------------------------------------- -- Coments: This is an implementation of the division algorithm. Dirent to the other implemented inverter -- in this, the division is performed directly. ---------------------------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_unsigned.all; use IEEE.STD_LOGIC_arith.all; ---------------------------------------------------------------------------------------------------- entity f2m_divider_163 is generic( NUM_BITS : positive := 163 ); port( x : in STD_LOGIC_VECTOR(NUM_BITS-1 downto 0); y : in STD_LOGIC_VECTOR(NUM_BITS-1 downto 0); clk : in STD_LOGIC; rst : in STD_LOGIC; done : out STD_LOGIC; x_div_y : out STD_LOGIC_VECTOR(NUM_BITS-1 downto 0) -- U = x/y mod Fx, ); end; ---------------------------------------------------------------------------------------------------- architecture behave of f2m_divider_163 is ---------------------------------------------------------------------------------------------------- -- m = 163, the irreductible polynomial constant p : std_logic_vector(NUM_BITS downto 0) := "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011001001"; -- control signals signal CASO: std_logic_vector(1 downto 0); signal c0, c1, c2, c3, c4, c5, c6, enA, enB, a_greater_b,a_eq_b: std_logic; signal A, B, U, V, X2, Y2, toB, toV: STD_LOGIC_VECTOR(NUM_BITS downto 0); -- Internal registers type CurrentState_type is (END_STATE, LOAD1, CYCLE); signal currentState: CurrentState_type; ---------------------------------------------------------------------------------------------------- begin ---------------------------------------------------------------------------------------------------- X2 <= x & '0'; Y2 <= y & '0'; caso <= "00" when A(0) = '0' and currentState = CYCLE else "01" when B(0) = '0' and currentState = CYCLE else "10" when a_greater_b = '1' and currentState = CYCLE else "11"; c0 <= '0' when caso = "01" else '1'; c1 <= '0' when caso = "00" else '1'; c2 <= '0' when caso = "01" else '1'; c3 <= '0' when caso = "00" else '1'; c4 <= '0' when CurrentState = Load1 else '1'; c5 <= '0' when rst = '1' or currentState = LOAD1 else '1'; c6 <= '0' when rst = '1' else '1'; enA <= '1' when currentState = LOAD1 or caso = "00" or caso = "10" else '0'; enB <= '1' when caso = "01" or caso = "11" or rst = '1' or currentstate = LOAD1 else '0'; a_greater_b <= '1' when A > B else '0'; a_eq_b <= '1' when A = B else '0'; celda_reg_A: entity celda_a(behave) port map( A, B, c0, c1, enA, rst, clk, toB, A); celda_reg_U: entity celda_U(behave) port map(U, V, P, c2, c3, c4, enA, rst, clk, toV, U); celda_reg_B: entity celda_B(behave) port map(toB, P , Y2, c5, c6, enB, clk, B); celda_reg_V: entity celda_v(behave) port map(toV, X2, c5, c6, enB, clk, V); ---------------------------------------------------------------------------------------------------- -- Finite state machine ---------------------------------------------------------------------------------------------------- EEAL: process (clk) begin -- syncronous reset if CLK'event and CLK = '1' then if rst = '1' then x_div_y <= (others => '0'); done <= '0'; currentState <= LOAD1; else case currentState is ----------------------------------------------------------------------------------- when LOAD1 => currentState <= Cycle; when CYCLE => if A_eq_B = '1' then currentState <= END_STATE; Done <= '1'; x_div_y <= U(NUM_BITS-1 downto 0); end if; ----------------------------------------------------------------------------------- when END_STATE => -- Do nothing currentState <= END_STATE; --done <= '0'; -- para generar el pulso, quitarlo entity caso contrario ----------------------------------------------------------------------------------- when others => null; end case; end if; end if; end process; end behave;
------------------------------------------------------------------------------ -- This file is a part of the GRLIB VHDL IP LIBRARY -- Copyright (C) 2003 - 2008, Gaisler Research -- Copyright (C) 2008 - 2014, Aeroflex Gaisler -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; either version 2 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------------- -- Copyright (C) 2009-2013, Aeroflex Gaisler AB ------------------------------------------------------------------------------- -- Entity: spw_2x_lvttl_pads -- File: spw_2x_lvttl_pads.vhd -- Author: Marko Isomaki, Aeroflex Gaisler -- Contact: [email protected] -- Description: pads for SpW signals in router ASIC LVTTL ports ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; library work; use work.config.all; library techmap; use techmap.gencomp.all; library grlib; use grlib.stdlib.conv_std_logic; entity spw_lvttl_pads is generic ( padtech : integer := 0; oepol : integer := 0; level : integer := 0; voltage : integer := 0; filter : integer := 0; strength : integer := 4; slew : integer := 0; input_type : integer := 0 ); port ( --------------------------------------------------------------------------- -- Signals going off-chip --------------------------------------------------------------------------- spw_rxd : in std_logic_vector(0 to CFG_SPW_NUM-1); spw_rxs : in std_logic_vector(0 to CFG_SPW_NUM-1); spw_txd : out std_logic_vector(0 to CFG_SPW_NUM-1); spw_txs : out std_logic_vector(0 to CFG_SPW_NUM-1); --------------------------------------------------------------------------- -- Signals to core --------------------------------------------------------------------------- lspw_rxd : out std_logic_vector(0 to CFG_SPW_NUM-1); lspw_rxs : out std_logic_vector(0 to CFG_SPW_NUM-1); lspw_txd : in std_logic_vector(0 to CFG_SPW_NUM-1); lspw_txs : in std_logic_vector(0 to CFG_SPW_NUM-1) ); end entity; architecture rtl of spw_lvttl_pads is begin ------------------------------------------------------------------------------ -- SpW port pads ------------------------------------------------------------------------------ spw_pads : for i in 0 to CFG_SPW_NUM-1 generate spw_pad_input: if input_type <= 3 generate spw_rxd_pad : inpad generic map ( tech => padtech, level => level, voltage => voltage, filter => filter, strength => strength) port map ( pad => spw_rxd(i), o => lspw_rxd(i)); spw_rxs_pad : inpad generic map ( tech => padtech, level => level, voltage => voltage, filter => filter, strength => strength) port map ( pad => spw_rxs(i), o => lspw_rxs(i)); end generate; spw_no_pad_input: if input_type >= 4 generate lspw_rxd(i) <= spw_rxd(i); lspw_rxs(i) <= spw_rxs(i); end generate; spw_txd_pad : outpad generic map ( tech => padtech, level => level, slew => slew, voltage => voltage, strength => strength) port map ( pad => spw_txd(i), i => lspw_txd(i)); spw_txs_pad : outpad generic map ( tech => padtech, level => level, slew => slew, voltage => voltage, strength => strength) port map ( pad => spw_txs(i), i => lspw_txs(i)); end generate; end;
---------------------------------------------------------------------------- --! @file --! @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved. --! @author Sergey Khabarov --! @brief Virtual clock multiplexer with buffered output. ------------------------------------------------------------------------------ library ieee; use ieee.std_logic_1164.all; library techmap; use techmap.gencomp.all; entity bufgmux_tech is generic ( tech : integer := 0; tmode_always_ena : boolean := false ); port ( O : out std_ulogic; I1 : in std_ulogic; I2 : in std_ulogic; S : in std_ulogic ); end; architecture rtl of bufgmux_tech is component bufgmux_fpga is generic ( tmode_always_ena : boolean := false ); port ( O : out std_ulogic; I1 : in std_ulogic; I2 : in std_ulogic; S : in std_ulogic ); end component; component bufgmux_micron180 is port ( O : out std_ulogic; I1 : in std_ulogic; I2 : in std_ulogic; S : in std_ulogic ); end component; begin inf : if tech = inferred generate O <= I1 when S = '0' else I2; end generate; xlnx : if tech = virtex6 or tech = kintex7 or tech = artix7 generate mux_buf : bufgmux_fpga generic map ( tmode_always_ena => tmode_always_ena ) port map ( O => O, I1 => I1, I2 => I2, S => S ); end generate; mic0 : if tech = micron180 generate mux_buf : bufgmux_micron180 port map ( O => O, I1 => I1, I2 => I2, S => S ); end generate; end;
---------------------------------------------------------------------------- --! @file --! @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved. --! @author Sergey Khabarov --! @brief Virtual clock multiplexer with buffered output. ------------------------------------------------------------------------------ library ieee; use ieee.std_logic_1164.all; library techmap; use techmap.gencomp.all; entity bufgmux_tech is generic ( tech : integer := 0; tmode_always_ena : boolean := false ); port ( O : out std_ulogic; I1 : in std_ulogic; I2 : in std_ulogic; S : in std_ulogic ); end; architecture rtl of bufgmux_tech is component bufgmux_fpga is generic ( tmode_always_ena : boolean := false ); port ( O : out std_ulogic; I1 : in std_ulogic; I2 : in std_ulogic; S : in std_ulogic ); end component; component bufgmux_micron180 is port ( O : out std_ulogic; I1 : in std_ulogic; I2 : in std_ulogic; S : in std_ulogic ); end component; begin inf : if tech = inferred generate O <= I1 when S = '0' else I2; end generate; xlnx : if tech = virtex6 or tech = kintex7 or tech = artix7 generate mux_buf : bufgmux_fpga generic map ( tmode_always_ena => tmode_always_ena ) port map ( O => O, I1 => I1, I2 => I2, S => S ); end generate; mic0 : if tech = micron180 generate mux_buf : bufgmux_micron180 port map ( O => O, I1 => I1, I2 => I2, S => S ); end generate; end;
-- tdp_ram_behav.vhd -- Copyright (C) 2017 VectorBlox Computing, Inc. -- -- Behavioural implementation of synchronous true dual-port RAM. -- Can either be read first or write first. library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; library work; use work.idram_utils.all; entity tdp_ram_behav is generic ( RAM_DEPTH : integer := 1024; RAM_WIDTH : integer := 8; WRITE_FIRST : boolean := false ); port ( address_a : in std_logic_vector(log2(RAM_DEPTH)-1 downto 0); address_b : in std_logic_vector(log2(RAM_DEPTH)-1 downto 0); clk : in std_logic; data_a : in std_logic_vector(RAM_WIDTH-1 downto 0); data_b : in std_logic_vector(RAM_WIDTH-1 downto 0); wren_a : in std_logic; wren_b : in std_logic; en_a : in std_logic; en_b : in std_logic; readdata_a : out std_logic_vector(RAM_WIDTH-1 downto 0); readdata_b : out std_logic_vector(RAM_WIDTH-1 downto 0) ); end tdp_ram_behav; architecture rtl of tdp_ram_behav is type ram_type is array (RAM_DEPTH-1 downto 0) of std_logic_vector(RAM_WIDTH-1 downto 0); shared variable ram : ram_type; begin read_first_gen : if not WRITE_FIRST generate process (clk) begin if rising_edge(clk) then if en_a = '1' then readdata_a <= ram(to_integer(unsigned(address_a))); if wren_a = '1' then ram(to_integer(unsigned(address_a))) := data_a; end if; end if; end if; end process; process (clk) begin if rising_edge(clk) then if en_b = '1' then readdata_b <= ram(to_integer(unsigned(address_b))); if wren_b = '1' then ram(to_integer(unsigned(address_b))) := data_b; end if; end if; end if; end process; end generate read_first_gen; write_first_gen : if WRITE_FIRST generate process (clk) begin if rising_edge(clk) then if en_a = '1' then if wren_a = '1' then ram(to_integer(unsigned(address_a))) := data_a; end if; readdata_a <= ram(to_integer(unsigned(address_a))); end if; end if; end process; process (clk) begin if rising_edge(clk) then if en_b = '1' then if wren_b = '1' then ram(to_integer(unsigned(address_b))) := data_b; end if; readdata_b <= ram(to_integer(unsigned(address_b))); end if; end if; end process; end generate write_first_gen; end rtl;
--------------------------------------------------------------------------------- -- Title : 1000 BASE X ability match -- Project : General Purpose Core --------------------------------------------------------------------------------- -- File : Eth1000BaseXAbilityMatch.vhd -- Author : Kurtis Nishimura --------------------------------------------------------------------------------- -- Description: -- Ability, acknowledge, consistency, idle match for Clause 37 auto-negotiation -- Next pages are not supported. --------------------------------------------------------------------------------- LIBRARY ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; use work.UtilityPkg.all; use work.Eth1000BaseXPkg.all; use work.GigabitEthPkg.all; entity Eth1000BaseXAbilityMatch is generic ( GATE_DELAY_G : time := 1 ns ); port ( -- System clock, reset & control ethRx62Clk : in sl; ethRx62Rst : in sl; -- Link is stable rxLinkSync : in sl; -- Entering a new state (abMatch should be reset on new state) newState : in sl; -- Output match signals abilityMatch : out sl; ability : out slv(15 downto 0); acknowledgeMatch : out sl; consistencyMatch : out sl; idleMatch : out sl; -- Physical Interface Signals phyRxData : in EthRxPhyLaneInType ); end Eth1000BaseXAbilityMatch; -- Define architecture architecture rtl of Eth1000BaseXAbilityMatch is type RegType is record ability : slv(15 downto 0); abCount : slv(2 downto 0); ackCount : slv(2 downto 0); idleCount : slv(2 downto 0); abMatch : sl; ackMatch : sl; consMatch : sl; idleMatch : sl; wordIsConfig : sl; end record RegType; constant REG_INIT_C : RegType := ( ability => (others => '0'), abCount => (others => '0'), ackCount => (others => '0'), idleCount => (others => '0'), abMatch => '0', ackMatch => '0', consMatch => '0', idleMatch => '0', wordIsConfig => '0' ); signal r : RegType := REG_INIT_C; signal rin : RegType; -- attribute dont_touch : string; -- attribute dont_touch of r : signal is "true"; begin comb : process(r,phyRxData,ethRx62Rst,rxLinkSync,newState) is variable v : RegType; begin v := r; -- Check for /C1/ or /C2/ if ( phyRxData.dataK = "01" and (phyRxData.data = OS_C1_C or phyRxData.data = OS_C2_C)) then v.wordIsConfig := '1'; else v.wordIsConfig := '0'; end if; -- On /I1/ or /I2/, reset abCount and ackCount if ( phyRxData.dataK = "01" and (phyRxData.data = OS_I1_C or phyRxData.dataK = OS_I2_C)) then v.abCount := (others => '0'); v.ackCount := (others => '0'); -- If we just saw /C1/ or /C2/ the next word is the ability word elsif (r.wordIsConfig = '1') then v.ability := phyRxData.data; -- If the ability word doesn't match the last one, reset the counter -- Note we ignore the ack bit in this comparison if (v.ability(15) /= r.ability(15) or (v.ability(13 downto 0) /= r.ability(13 downto 0))) then v.abCount := (others => '0'); -- Otherwise, we match. Increment the ability count elsif (r.abCount < 3) then v.abCount := r.abCount + 1; end if; -- For acknowledge, need a match and the ack bit set or we reset if (v.ability /= r.ability or (r.ability(14) = '0')) then v.ackCount := (others => '0'); -- Otherwise, we match. Increment the ability count elsif (r.ackCount < 3) then v.ackCount := r.ackCount + 1; end if; end if; -- On /C1/ or /C2/, reset idle count if ( r.wordIsConfig = '1' ) then v.idleCount := (others => '0'); -- If see /I1/ or /I2/ increment the idle count elsif (phyRxData.dataK = "01" and (phyRxData.data = OS_I1_C or phyRxData.data = OS_I2_C) ) then if (r.idleCount < 3) then v.idleCount := r.idleCount + 1; end if; end if; -- If the ability count is 3, we're matched if (r.abCount = 3) then v.abMatch := '1'; -- Otherwise, we're not else v.abMatch := '0'; end if; -- If the acknowledge count is 3, we're matched if (r.ackCount = 3) then v.ackMatch := '1'; -- Otherwise, we're not else v.ackMatch := '0'; end if; -- If the idle count is 3, we're matched if (r.idleCount = 3) then v.idleMatch := '1'; -- Otherwise, we're not else v.idleMatch := '0'; end if; -- Check for consistency match if (v.abMatch = '1' and v.ackMatch = '1') then v.consMatch := '1'; else v.consMatch := '0'; end if; -- Reset on ethernet reset or sync down if (ethRx62Rst = '1' or rxLinkSync = '0' or newState = '1') then v := REG_INIT_C; end if; -- Outputs to ports abilityMatch <= r.abMatch; acknowledgeMatch <= r.ackMatch; consistencyMatch <= r.consMatch; idleMatch <= r.idleMatch; ability <= r.ability; rin <= v; end process; seq : process (ethRx62Clk) is begin if (rising_edge(ethRx62Clk)) then r <= rin after GATE_DELAY_G; end if; end process seq; end rtl;
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.MATH_REAL.ALL; use std.textio.all; use work.all; use work.dbgsnap; entity dbgsnap_testbench is port(done : out boolean); end; architecture structural of dbgsnap_testbench is signal finished : boolean; signal clk : boolean; signal tr : std_logic; signal dbg_in : unsigned(15 downto 0):= to_unsigned(0,16); function to_stdulogic( V: Boolean ) return std_ulogic is begin if V then return '1'; else return '0'; end if; end to_stdulogic; begin done <= finished; -- pragma translate_off process is begin clk <= false; wait for 3 ns; while (not finished) loop clk <= not clk; wait for 500 ns; clk <= not clk; wait for 500 ns; end loop; wait; end process; process is begin wait for 3 ns; while (not finished) loop dbg_in <= dbg_in + 1; wait for 1000 ns; end loop; wait; end process; -- pragma translate_on -- pragma translate_off -- pragma translate_on totest : entity dbgsnap port map ( clk => to_stdulogic(clk) , tr => tr , dbg_in => std_logic_vector(dbg_in) ); tr <= -- pragma translate_off '0', -- pragma translate_on '1' -- pragma translate_off after 1000 ns -- pragma translate_on ; finished <= -- pragma translate_off false, -- pragma translate_on true -- pragma translate_off after 8200000 ns -- pragma translate_on ; end;
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; use IEEE.MATH_REAL.ALL; use std.textio.all; use work.all; use work.dbgsnap; entity dbgsnap_testbench is port(done : out boolean); end; architecture structural of dbgsnap_testbench is signal finished : boolean; signal clk : boolean; signal tr : std_logic; signal dbg_in : unsigned(15 downto 0):= to_unsigned(0,16); function to_stdulogic( V: Boolean ) return std_ulogic is begin if V then return '1'; else return '0'; end if; end to_stdulogic; begin done <= finished; -- pragma translate_off process is begin clk <= false; wait for 3 ns; while (not finished) loop clk <= not clk; wait for 500 ns; clk <= not clk; wait for 500 ns; end loop; wait; end process; process is begin wait for 3 ns; while (not finished) loop dbg_in <= dbg_in + 1; wait for 1000 ns; end loop; wait; end process; -- pragma translate_on -- pragma translate_off -- pragma translate_on totest : entity dbgsnap port map ( clk => to_stdulogic(clk) , tr => tr , dbg_in => std_logic_vector(dbg_in) ); tr <= -- pragma translate_off '0', -- pragma translate_on '1' -- pragma translate_off after 1000 ns -- pragma translate_on ; finished <= -- pragma translate_off false, -- pragma translate_on true -- pragma translate_off after 8200000 ns -- pragma translate_on ; end;
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc719.vhd,v 1.2 2001-10-26 16:29:59 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c01s01b00x00p04n01i00719ent IS BEGIN END; -- No_Failure_Here ENTITY c01s01b00x00p04n01i00719ent IS END c01s01b00x00p04n01i00719ent; ARCHITECTURE c01s01b00x00p04n01i00719arch OF c01s01b00x00p04n01i00719ent IS BEGIN TESTING: PROCESS BEGIN assert FALSE report "***PASSED TEST: c01s01b00x00p04n01i00719" severity NOTE; wait; END PROCESS TESTING; END c01s01b00x00p04n01i00719arch;
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc719.vhd,v 1.2 2001-10-26 16:29:59 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c01s01b00x00p04n01i00719ent IS BEGIN END; -- No_Failure_Here ENTITY c01s01b00x00p04n01i00719ent IS END c01s01b00x00p04n01i00719ent; ARCHITECTURE c01s01b00x00p04n01i00719arch OF c01s01b00x00p04n01i00719ent IS BEGIN TESTING: PROCESS BEGIN assert FALSE report "***PASSED TEST: c01s01b00x00p04n01i00719" severity NOTE; wait; END PROCESS TESTING; END c01s01b00x00p04n01i00719arch;
-- Copyright (C) 2001 Bill Billowitch. -- Some of the work to develop this test suite was done with Air Force -- support. The Air Force and Bill Billowitch assume no -- responsibilities for this software. -- This file is part of VESTs (Vhdl tESTs). -- VESTs is free software; you can redistribute it and/or modify it -- under the terms of the GNU General Public License as published by the -- Free Software Foundation; either version 2 of the License, or (at -- your option) any later version. -- VESTs is distributed in the hope that it will be useful, but WITHOUT -- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- for more details. -- You should have received a copy of the GNU General Public License -- along with VESTs; if not, write to the Free Software Foundation, -- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -- --------------------------------------------------------------------- -- -- $Id: tc719.vhd,v 1.2 2001-10-26 16:29:59 paw Exp $ -- $Revision: 1.2 $ -- -- --------------------------------------------------------------------- ENTITY c01s01b00x00p04n01i00719ent IS BEGIN END; -- No_Failure_Here ENTITY c01s01b00x00p04n01i00719ent IS END c01s01b00x00p04n01i00719ent; ARCHITECTURE c01s01b00x00p04n01i00719arch OF c01s01b00x00p04n01i00719ent IS BEGIN TESTING: PROCESS BEGIN assert FALSE report "***PASSED TEST: c01s01b00x00p04n01i00719" severity NOTE; wait; END PROCESS TESTING; END c01s01b00x00p04n01i00719arch;
-- A simple frequency divider library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity divider is -- 1 -- f_out = f_in ----- -- 2 * n generic (n: natural range 1 to 2147483647); port ( clk_in : in std_logic; nrst : in std_logic; clk_out : out std_logic ); end entity divider; architecture counter of divider is signal cnt : integer range 0 to n - 1; signal internal_clk_out : std_logic := '0'; begin clk_out <= internal_clk_out; process (clk_in, nrst) begin if nrst = '0' then cnt <= 0; internal_clk_out <= '0'; elsif rising_edge (clk_in) then if cnt = n - 1 then cnt <= 0; internal_clk_out <= not internal_clk_out; else cnt <= cnt + 1; end if; end if; end process; end architecture counter;
entity tb_func08b is end tb_func08b; library ieee; use ieee.std_logic_1164.all; architecture behav of tb_func08b is signal v : std_ulogic_vector(3 downto 0); signal r : integer; begin dut: entity work.func08b port map (v, r); process begin v <= x"0"; wait for 1 ns; assert r = 4 severity failure; v <= x"1"; wait for 1 ns; assert r = 3 severity failure; v <= x"8"; wait for 1 ns; assert r = 0 severity failure; v <= x"3"; wait for 1 ns; assert r = 2 severity failure; wait; end process; end behav;
entity record_test is port ( o : out integer ); end record_test; architecture rtl of record_test is type t_record is record int : integer range 0 to 15; end record t_record; constant rec_constant : t_record := (int => 8); signal int_signal : integer range 0 to rec_constant.int := 4; begin o <= int_signal; end rtl;
------------------------------------------------------------------------------- -- -- Synthesizable model of TI's TMS9918A, TMS9928A, TMS9929A. -- -- $Id: vdp18_core.vhd,v 1.28 2006/06/18 10:47:01 arnim Exp $ -- -- Core Toplevel -- -- Notes: -- This core implements a simple VRAM interface which is suitable for a -- synchronous SRAM component. There is currently no support of the -- original DRAM interface. -- -- Please be aware that the colors might me slightly different from the -- original TMS9918. It is assumed that the simplified conversion to RGB -- encoding is equivalent to the compatability mode of the V9938. -- Implementing a 100% correct color encoding for RGB would require -- significantly more logic and 8-bit wide RGB DACs. -- -- References: -- -- * TI Data book TMS9918.pdf -- http://www.bitsavers.org/pdf/ti/_dataBooks/TMS9918.pdf -- -- * Sean Young's tech article: -- http://bifi.msxnet.org/msxnet/tech/tms9918a.txt -- -- * Paul Urbanus' discussion of the timing details -- http://bifi.msxnet.org/msxnet/tech/tmsposting.txt -- -- * Richard F. Drushel's article series -- "This Week With My Coleco ADAM" -- http://junior.apk.net/~drushel/pub/coleco/twwmca/index.html -- ------------------------------------------------------------------------------- -- -- Copyright (c) 2006, Arnim Laeuger ([email protected]) -- -- All rights reserved -- -- Redistribution and use in source and synthezised forms, with or without -- modification, are permitted provided that the following conditions are met: -- -- Redistributions of source code must retain the above copyright notice, -- this list of conditions and the following disclaimer. -- -- Redistributions in synthesized form must reproduce the above copyright -- notice, this list of conditions and the following disclaimer in the -- documentation and/or other materials provided with the distribution. -- -- Neither the name of the author nor the names of other contributors may -- be used to endorse or promote products derived from this software without -- specific prior written permission. -- -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. -- -- Please report bugs to the author, but before you do so, please -- make sure that this is not a derivative work and that -- you have the latest version of this file. -- -- 2016/11 - Some changes by Fabio Belavenuto ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use ieee.std_logic_unsigned.all; use work.vdp18_pack.opmode_t; use work.vdp18_pack.hv_t; use work.vdp18_pack.access_t; use work.vdp18_pack.to_boolean_f; use work.vdp18_pack.to_std_logic_f; entity vdp18_core is generic ( video_opt_g : integer := 0 -- 0 = no dblscan, 1 = dblscan configurable, 2 = dblscan always enabled, 3 = no dblscan and external palette ); port ( -- Global Interface ------------------------------------------------------- clock_i : in std_logic; clk_en_10m7_i : in std_logic; por_i : in std_logic; reset_i : in std_logic; -- CPU Interface ---------------------------------------------------------- csr_n_i : in std_logic; csw_n_i : in std_logic; mode_i : in std_logic_vector( 0 to 1); int_n_o : out std_logic; cd_i : in std_logic_vector( 0 to 7); cd_o : out std_logic_vector( 0 to 7); wait_o : out std_logic; -- VRAM Interface --------------------------------------------------------- vram_ce_o : out std_logic; vram_oe_o : out std_logic; vram_we_o : out std_logic; vram_a_o : out std_logic_vector( 0 to 13); vram_d_o : out std_logic_vector( 0 to 7); vram_d_i : in std_logic_vector( 0 to 7); -- Video Interface -------------------------------------------------------- vga_en_i : in std_logic; scanline_en_i : in std_logic; cnt_hor_o : out std_logic_vector( 8 downto 0); cnt_ver_o : out std_logic_vector( 7 downto 0); rgb_r_o : out std_logic_vector( 0 to 3); rgb_g_o : out std_logic_vector( 0 to 3); rgb_b_o : out std_logic_vector( 0 to 3); hsync_n_o : out std_logic; vsync_n_o : out std_logic; ntsc_pal_i : in std_logic; -- 0 = NTSC vertfreq_csw_o : out std_logic; vertfreq_d_o : out std_logic ); end vdp18_core; architecture struct of vdp18_core is signal por_s : boolean; signal reset_s : boolean; signal clk_en_10m7_s, clk_en_5m37_s, -- clk_en_3m58_s, clk_en_acc_s : boolean; signal opmode_s : opmode_t; signal access_type_s : access_t; signal num_pix_s, num_line_s : hv_t; signal rgb_hsync_n_s : std_logic; signal rgb_vsync_n_s : std_logic; signal vga_hsync_n_s : std_logic; signal vga_vsync_n_s : std_logic; signal blank_s : boolean; signal vert_inc_s : boolean; signal reg_blank_s, reg_size1_s, reg_mag1_s : boolean; signal spr_5th_s : boolean; signal spr_5th_num_s : std_logic_vector(0 to 4); signal stop_sprite_s : boolean; signal vert_active_s, hor_active_s : boolean; signal rd_s, wr_s : boolean; signal reg_ntb_s : std_logic_vector(0 to 3); signal reg_ctb_s : std_logic_vector(0 to 7); signal reg_pgb_s : std_logic_vector(0 to 2); signal reg_satb_s : std_logic_vector(0 to 6); signal reg_spgb_s : std_logic_vector(0 to 2); signal reg_col1_s, reg_col0_s : std_logic_vector(0 to 3); signal cpu_vram_a_s : std_logic_vector(0 to 13); signal pat_table_s : std_logic_vector(0 to 9); signal pat_name_s : std_logic_vector(0 to 7); signal pat_col_s : std_logic_vector(0 to 3); signal spr_num_s : std_logic_vector(0 to 4); signal spr_line_s : std_logic_vector(0 to 3); signal spr_name_s : std_logic_vector(0 to 7); signal spr0_col_s, spr1_col_s, spr2_col_s, spr3_col_s : std_logic_vector(0 to 3); signal spr_coll_s : boolean; signal irq_s : boolean; signal vram_read_s : boolean; signal vram_write_s : boolean; signal col_s : std_logic_vector(0 to 3); signal col_rgb_s : std_logic_vector(0 to 3); signal col_vga_s : std_logic_vector(0 to 3); signal rgb_s : std_logic_vector(0 to 15); signal palette_idx_s : std_logic_vector(0 to 3); signal palette_val_s : std_logic_vector(0 to 15); signal palette_wr_s : std_logic; signal ntsc_pal_e_s : std_logic; signal oddline_s : std_logic := '0'; begin clk_en_10m7_s <= to_boolean_f(clk_en_10m7_i); rd_s <= not to_boolean_f(csr_n_i); wr_s <= not to_boolean_f(csw_n_i); por_s <= por_i = '1'; reset_s <= reset_i = '1'; ----------------------------------------------------------------------------- -- Clock Generator ----------------------------------------------------------------------------- clk_gen_b: entity work.vdp18_clk_gen port map ( clock_i => clock_i, clk_en_10m7_i => clk_en_10m7_i, reset_i => por_s, clk_en_5m37_o => clk_en_5m37_s, clk_en_3m58_o => open, --clk_en_3m58_s, clk_en_2m68_o => open ); ----------------------------------------------------------------------------- -- Horizontal and Vertical Timing Generator ----------------------------------------------------------------------------- hor_vert_b: entity work.vdp18_hor_vert port map ( clock_i => clock_i, clk_en_5m37_i => clk_en_5m37_s, reset_i => por_s, opmode_i => opmode_s, ntsc_pal_i => ntsc_pal_e_s, num_pix_o => num_pix_s, num_line_o => num_line_s, vert_inc_o => vert_inc_s, hsync_n_o => rgb_hsync_n_s, vsync_n_o => rgb_vsync_n_s, blank_o => blank_s, cnt_hor_o => cnt_hor_o, cnt_ver_o => cnt_ver_o ); ----------------------------------------------------------------------------- -- Control Module ----------------------------------------------------------------------------- ctrl_b: entity work.vdp18_ctrl port map ( clock_i => clock_i, clk_en_5m37_i => clk_en_5m37_s, reset_i => reset_s, opmode_i => opmode_s, vram_read_i => vram_read_s, vram_write_i => vram_write_s, vram_ce_o => vram_ce_o, vram_oe_o => vram_oe_o, num_pix_i => num_pix_s, num_line_i => num_line_s, vert_inc_i => vert_inc_s, reg_blank_i => reg_blank_s, reg_size1_i => reg_size1_s, stop_sprite_i => stop_sprite_s, clk_en_acc_o => clk_en_acc_s, access_type_o => access_type_s, vert_active_o => vert_active_s, hor_active_o => hor_active_s, irq_o => irq_s ); ----------------------------------------------------------------------------- -- CPU I/O Module ----------------------------------------------------------------------------- cpu_io_b: entity work.vdp18_cpuio port map ( clock_i => clock_i, clk_en_10m7_i => clk_en_10m7_s, clk_en_acc_i => clk_en_acc_s, reset_i => por_s, rd_i => rd_s, wr_i => wr_s, mode_i => mode_i, cd_i => cd_i, cd_o => cd_o, cd_oe_o => open, wait_o => wait_o, access_type_i => access_type_s, opmode_o => opmode_s, vram_read_o => vram_read_s, vram_write_o => vram_write_s, vram_we_o => vram_we_o, vram_a_o => cpu_vram_a_s, vram_d_o => vram_d_o, vram_d_i => vram_d_i, spr_coll_i => spr_coll_s, spr_5th_i => spr_5th_s, spr_5th_num_i => spr_5th_num_s, reg_ev_o => open, reg_16k_o => open, reg_blank_o => reg_blank_s, reg_size1_o => reg_size1_s, reg_mag1_o => reg_mag1_s, reg_ntb_o => reg_ntb_s, reg_ctb_o => reg_ctb_s, reg_pgb_o => reg_pgb_s, reg_satb_o => reg_satb_s, reg_spgb_o => reg_spgb_s, reg_col1_o => reg_col1_s, reg_col0_o => reg_col0_s, palette_idx_o => palette_idx_s, palette_val_o => palette_val_s, palette_wr_o => palette_wr_s, irq_i => irq_s, int_n_o => int_n_o, vertfreq_csw_o => vertfreq_csw_o, vertfreq_d_o => vertfreq_d_o ); ----------------------------------------------------------------------------- -- VRAM Address Multiplexer ----------------------------------------------------------------------------- addr_mux_b: entity work.vdp18_addr_mux port map ( access_type_i => access_type_s, opmode_i => opmode_s, num_line_i => num_line_s, reg_ntb_i => reg_ntb_s, reg_ctb_i => reg_ctb_s, reg_pgb_i => reg_pgb_s, reg_satb_i => reg_satb_s, reg_spgb_i => reg_spgb_s, reg_size1_i => reg_size1_s, cpu_vram_a_i => cpu_vram_a_s, pat_table_i => pat_table_s, pat_name_i => pat_name_s, spr_num_i => spr_num_s, spr_line_i => spr_line_s, spr_name_i => spr_name_s, vram_a_o => vram_a_o ); ----------------------------------------------------------------------------- -- Pattern Generator ----------------------------------------------------------------------------- pattern_b: entity work.vdp18_pattern port map ( clock_i => clock_i, clk_en_5m37_i => clk_en_5m37_s, clk_en_acc_i => clk_en_acc_s, reset_i => reset_s, opmode_i => opmode_s, access_type_i => access_type_s, num_line_i => num_line_s, vram_d_i => vram_d_i, vert_inc_i => vert_inc_s, vsync_n_i => rgb_vsync_n_s, reg_col1_i => reg_col1_s, reg_col0_i => reg_col0_s, pat_table_o => pat_table_s, pat_name_o => pat_name_s, pat_col_o => pat_col_s ); ----------------------------------------------------------------------------- -- Sprite Generator ----------------------------------------------------------------------------- sprite_b: entity work.vdp18_sprite port map ( clock_i => clock_i, clk_en_5m37_i => clk_en_5m37_s, clk_en_acc_i => clk_en_acc_s, reset_i => reset_s, access_type_i => access_type_s, num_pix_i => num_pix_s, num_line_i => num_line_s, vram_d_i => vram_d_i, vert_inc_i => vert_inc_s, reg_size1_i => reg_size1_s, reg_mag1_i => reg_mag1_s, spr_5th_o => spr_5th_s, spr_5th_num_o => spr_5th_num_s, stop_sprite_o => stop_sprite_s, spr_coll_o => spr_coll_s, spr_num_o => spr_num_s, spr_line_o => spr_line_s, spr_name_o => spr_name_s, spr0_col_o => spr0_col_s, spr1_col_o => spr1_col_s, spr2_col_o => spr2_col_s, spr3_col_o => spr3_col_s ); ----------------------------------------------------------------------------- -- Color Multiplexer ----------------------------------------------------------------------------- col_mux_b: entity work.vdp18_col_mux port map ( vert_active_i => vert_active_s, hor_active_i => hor_active_s, blank_i => blank_s, reg_col0_i => reg_col0_s, pat_col_i => pat_col_s, spr0_col_i => spr0_col_s, spr1_col_i => spr1_col_s, spr2_col_i => spr2_col_s, spr3_col_i => spr3_col_s, col_o => col_rgb_s ); von3: if video_opt_g /= 3 generate ntsc_pal_e_s <= ntsc_pal_i; ----------------------------------------------------------------------------- -- Palette memory ----------------------------------------------------------------------------- palette: entity work.vdp18_palette port map ( reset_i => reset_s, clock_i => clock_i, we_i => palette_wr_s, addr_wr_i => palette_idx_s, data_i => palette_val_s, addr_rd_i => col_s, data_o => rgb_s ); ----------------------------------------------------------------------------- -- Process rgb_reg -- -- Purpose: -- Converts the color information to simple RGB and saves these in -- output registers. -- rgb_reg: process (clock_i, por_s) begin if por_s then rgb_r_o <= (others => '0'); rgb_g_o <= (others => '0'); rgb_b_o <= (others => '0'); elsif rising_edge(clock_i) then if clk_en_10m7_s then if scanline_en_i = '1' and vga_en_i = '1' then if rgb_s( 0 to 3) > 1 and oddline_s = '1' then rgb_r_o <= rgb_s( 0 to 3) - 2; else rgb_r_o <= rgb_s( 0 to 3); end if; if rgb_s(12 to 15) > 1 and oddline_s = '1' then rgb_g_o <= rgb_s(12 to 15) - 2; else rgb_g_o <= rgb_s(12 to 15); end if; if rgb_s( 4 to 7) > 1 and oddline_s = '1' then rgb_b_o <= rgb_s( 4 to 7) - 2; else rgb_b_o <= rgb_s( 4 to 7); end if; else rgb_r_o <= rgb_s( 0 to 3); rgb_g_o <= rgb_s(12 to 15); rgb_b_o <= rgb_s( 4 to 7); end if; end if; end if; end process rgb_reg; -- ----------------------------------------------------------------------------- end generate; vo0: if video_opt_g = 0 generate col_s <= col_rgb_s; hsync_n_o <= rgb_hsync_n_s; vsync_n_o <= rgb_vsync_n_s; end generate; vo3: if video_opt_g = 3 generate ntsc_pal_e_s <= '0'; -- Only NTSC rgb_r_o <= col_rgb_s; rgb_g_o <= (others => '0'); rgb_b_o <= (others => '0'); hsync_n_o <= rgb_hsync_n_s; vsync_n_o <= rgb_vsync_n_s; end generate; vo1_2: if video_opt_g = 1 or video_opt_g = 2 generate col_s <= col_vga_s when vga_en_i = '1' or video_opt_g = 2 else col_rgb_s; scandbl: entity work.dblscan port map ( -- NOTE CLOCKS MUST BE PHASE LOCKED !! clk_6m_i => clock_i, clk_en_6m_i => to_std_logic_f(clk_en_5m37_s), clk_12m_i => clock_i, clk_en_12m_i => to_std_logic_f(clk_en_10m7_s), col_i => col_rgb_s, col_o => col_vga_s, oddline_o => oddline_s, hsync_n_i => rgb_hsync_n_s, vsync_n_i => rgb_vsync_n_s, hsync_n_o => vga_hsync_n_s, vsync_n_o => vga_vsync_n_s ); hsync_n_o <= vga_hsync_n_s when vga_en_i = '1' or video_opt_g = 2 else rgb_hsync_n_s; vsync_n_o <= vga_vsync_n_s when vga_en_i = '1' or video_opt_g = 2 else rgb_vsync_n_s; end generate; end architecture;
---------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 20:00:58 11/19/2013 -- Design Name: -- Module Name: My_PC_Adder_948282 - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --use IEEE.NUMERIC_STD.ALL; -- Uncomment the following library declaration if instantiating -- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity My_PC_Adder_948282 is Port ( Address_In : in STD_LOGIC_VECTOR (9 downto 0); Address_Next : out STD_LOGIC_VECTOR (9 downto 0)); end My_PC_Adder_948282; architecture Behavioral of My_PC_Adder_948282 is component My_Adder_948282 is Port ( A_element : in STD_LOGIC; B_element : in STD_LOGIC; CarryIn : in STD_LOGIC; CarryOut : out STD_LOGIC; Result : out STD_LOGIC); end component; signal sig1: std_logic; signal sig2, sig3, sig4, sig5, sig6, sig7, sig8, sig9, sig10: std_logic; begin u0: My_Adder_948282 port map (A_element=>Address_In(0), B_element=>'1', CarryIn=>'0', Result=>Address_Next(0), CarryOut=>sig1); u1: My_Adder_948282 port map (A_element=>Address_In(1), B_element=>'0', CarryIn=>sig1, Result=>Address_Next(1), CarryOut=>sig2); u2: My_Adder_948282 port map (A_element=>Address_In(2), B_element=>'0', CarryIn=>sig2, Result=>Address_Next(2), CarryOut=>sig3); u3: My_Adder_948282 port map (A_element=>Address_In(3), B_element=>'0', CarryIn=>sig3, Result=>Address_Next(3), CarryOut=>sig4); u4: My_Adder_948282 port map (A_element=>Address_In(4), B_element=>'0', CarryIn=>sig4, Result=>Address_Next(4), CarryOut=>sig5); u5: My_Adder_948282 port map (A_element=>Address_In(5), B_element=>'0', CarryIn=>sig5, Result=>Address_Next(5), CarryOut=>sig6); u6: My_Adder_948282 port map (A_element=>Address_In(6), B_element=>'0', CarryIn=>sig6, Result=>Address_Next(6), CarryOut=>sig7); u7: My_Adder_948282 port map (A_element=>Address_In(7), B_element=>'0', CarryIn=>sig7, Result=>Address_Next(7), CarryOut=>sig8); u8: My_Adder_948282 port map (A_element=>Address_In(8), B_element=>'0', CarryIn=>sig8, Result=>Address_Next(8), CarryOut=>sig9); u9: My_Adder_948282 port map (A_element=>Address_In(9), B_element=>'0', CarryIn=>sig9, Result=>Address_Next(9), CarryOut=>sig10); end Behavioral;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;
package body badger is end package body; package body badger2 is end package body badger2; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity accumulator is port ( a: in std_logic_vector(3 downto 0); clk, reset: in std_logic; accum: out std_logic_vector(3 downto 0) ); end accumulator; architecture simple of accumulator is signal accumL: unsigned(3 downto 0); begin accumulate: process (clk, reset) begin if (reset = '1') then accumL <= "0000"; elsif (clk'event and clk= '1') then accumL <= accumL + to_unsigned(a); end if; end process; accum <= std_logic_vector(accumL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity adder is port ( a,b : in std_logic_vector (15 downto 0); sum: out std_logic_vector (15 downto 0) ); end adder; architecture dataflow of adder is begin sum <= a + b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity pAdderAttr is generic(n : integer := 8); port (a : in std_logic_vector(n - 1 downto 0); b : in std_logic_vector(n - 1 downto 0); cin : in std_logic; sum : out std_logic_vector(n - 1 downto 0); cout : out std_logic); end pAdderAttr; architecture loopDemo of pAdderAttr is begin process(a, b, cin) variable carry: std_logic_vector(sum'length downto 0); variable localSum: std_logic_vector(sum'high downto 0); begin carry(0) := cin; for i in sum'reverse_range loop localSum(i) := (a(i) xor b(i)) xor carry(i); carry(i + 1) := (a(i) and b(i)) or (carry(i) and (a(i) or b(i))); end loop; sum <= localSum; cout <= carry(carry'high - 1); end process; end loopDemo; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in unsigned(3 downto 0); sum: out unsigned(3 downto 0) ); end adder; architecture simple of adder is begin sum <= a + b; end simple; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity asyncLoad is port ( loadVal, d: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLoad; architecture rtl of asyncLoad is begin process (clk, load, loadVal) begin if (load = '1') then q <= loadVal; elsif (clk'event and clk = '1' ) then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity BidirBuf is port ( OE: in std_logic; input: in std_logic_vector; output: out std_logic_vector ); end BidirBuf; architecture behavioral of BidirBuf is begin bidirBuf: process (OE, input) begin if (OE = '1') then output <= input; else output <= (others => 'Z'); end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BidirCnt is port ( OE: in std_logic; CntEnable: in std_logic; LdCnt: in std_logic; Clk: in std_logic; Rst: in std_logic; Cnt: inout std_logic_vector(3 downto 0) ); end BidirCnt; architecture behavioral of BidirCnt is component LoadCnt port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end component; component BidirBuf port ( OE: in std_logic; input: in std_logic_vector; output: inout std_logic_vector ); end component; signal CntVal: std_logic_vector(3 downto 0); signal LoadVal: std_logic_vector(3 downto 0); begin u1: loadcnt port map (CntEn => CntEnable, LdCnt => LdCnt, LdData => LoadVal, Clk => Clk, Rst => Rst, CntVal => CntVal ); u2: bidirbuf port map (OE => oe, input => CntVal, output => Cnt ); LoadVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity bidirbuffer is port ( input: in std_logic; enable: in std_logic; feedback: out std_logic; output: inout std_logic ); end bidirbuffer; architecture structural of bidirbuffer is begin u1: bidir port map (ip => input, oe => enable, op_fb => feedback, op => output ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity clkGen is port ( clk: in std_logic; reset: in std_logic; ClkDiv2, ClkDiv4, ClkDiv6,ClkDiv8: out std_logic ); end clkGen; architecture behav of clkGen is subtype numClks is std_logic_vector(1 to 4); subtype numPatterns is integer range 0 to 11; type clkTableType is array (numpatterns'low to numPatterns'high) of numClks; constant clkTable: clkTableType := clkTableType'( -- ClkDiv8______ -- ClkDiv6_____ | -- ClkDiv4____ || -- ClkDiv2 __ ||| -- |||| "1111", "0111", "1011", "0001", "1100", "0100", "1010", "0010", "1111", "0001", "1001", "0101"); signal index: numPatterns; begin lookupTable: process (clk, reset) begin if reset = '1' then index <= 0; elsif (clk'event and clk = '1') then if index = numPatterns'high then index <= numPatterns'low; else index <= index + 1; end if; end if; end process; (ClkDiv2,ClkDiv4,ClkDiv6,ClkDiv8) <= clkTable(index); end behav; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; enable: in std_logic; reset: in std_logic; count: buffer unsigned(3 downto 0) ); end counter; architecture simple of counter is begin increment: process (clk, reset) begin if reset = '1' then count <= "0000"; elsif(clk'event and clk = '1') then if enable = '1' then count <= count + 1; else count <= count; end if; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; use work.scaleable.all; entity count8 is port ( clk: in std_logic; rst: in std_logic; count: out std_logic_vector(7 downto 0) ); end count8; architecture structural of count8 is begin u1: scaleUpCnt port map (clk => clk, reset => rst, cnt => count ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 9) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 9); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(3,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(9 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(9 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= to_unsigned(0,10); elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; enable: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); elsif (enable = '1') then countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; load: in std_logic; data: in std_logic_vector(3 downto 0); count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then if (load = '1') then countL <= to_unsigned(data); else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity Cnt4Term is port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic ); end Cnt4Term; architecture behavioral of Cnt4Term is signal CntL: unsigned(3 downto 0); begin increment: process begin wait until clk = '1'; CntL <= CntL + 1; end process; Cnt <= to_stdlogicvector(CntL); TermCnt <= '1' when CntL = "1111" else '0'; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity Counter is port ( clock: in std_logic; Count: out std_logic_vector(3 downto 0) ); end Counter; architecture structural of Counter is component Cnt4Term port ( clk: in std_logic; Cnt: out std_logic_vector(3 downto 0); TermCnt: out std_logic); end component; begin u1: Cnt4Term port map (clk => clock, Cnt => Count, TermCnt => open ); end structural; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if(clk'event and clk = '1') then if (reset = '1') then countL <= "0000"; else countL <= countL + 1; end if; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity convertArith is port ( truncate: out unsigned(3 downto 0); extend: out unsigned(15 downto 0); direction: out unsigned(0 to 7) ); end convertArith; architecture simple of convertArith is constant Const: unsigned(7 downto 0) := "00111010"; begin truncate <= resize(Const, truncate'length); extend <= resize(Const, extend'length); direction <= resize(Const, direction'length); end simple; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is constant THREE: std_logic_vector(1 downto 0) := "11"; begin y <= '1' when (a & b = THREE) or (c & d /= THREE) else '0'; end concurrent; -- incorporates Errata 12.1 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity typeConvert is port ( a: out unsigned(7 downto 0) ); end typeConvert; architecture simple of typeConvert is constant Const: natural := 43; begin a <= To_unsigned(Const,8); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk) begin if (clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(0 to 3) ); end counter; architecture simple of counter is signal countL: unsigned(0 to 3); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "0000"; elsif(clk'event and clk = '1') then countL <= countL + "001"; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if reset = '1' then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + 1; end if; end process; count <= std_logic_vector(countL); end simple; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity counter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end counter; architecture simple of counter is signal countL: unsigned(3 downto 0); begin increment: process (clk, reset) begin if (reset = '1') then countL <= "1001"; elsif(clk'event and clk = '1') then countL <= countL + "0001"; end if; end process; count <= std_logic_vector(countL); end simple; library IEEE; use IEEE.std_logic_1164.all; use work.decProcs.all; entity decoder is port ( decIn: in std_logic_vector(1 downto 0); decOut: out std_logic_vector(3 downto 0) ); end decoder; architecture simple of decoder is begin DEC2x4(decIn,decOut); end simple; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); decOut_n: out std_logic_vector(5 downto 0) ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; alias sio_dec_n: std_logic is decOut_n(5); alias rst_ctrl_rd_n: std_logic is decOut_n(4); alias atc_stat_rd_n: std_logic is decOut_n(3); alias mgmt_stat_rd_n: std_logic is decOut_n(2); alias io_int_stat_rd_n: std_logic is decOut_n(1); alias int_ctrl_rd_n: std_logic is decOut_n(0); alias upper: std_logic_vector(2 downto 0) is dev_adr(19 downto 17); alias CtrlBits: std_logic_vector(16 downto 0) is dev_adr(16 downto 0); begin decoder: process (upper, CtrlBits) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case upper is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case CtrlBits is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr) begin -- Set defaults for outputs sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin sio_dec_n <= '0' when dev_adr (19 downto 17) = SuperIORange else '1'; int_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IntCtrlReg) else '1'; io_int_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = IoIntStatReg) else '1'; rst_ctrl_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = RstCtrlReg) else '1'; atc_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = AtcStatusReg) else '1'; mgmt_stat_rd_n <= '0' when (dev_adr (19 downto 17) = CtrlRegRange) and (dev_adr(16 downto 0) = MgmtStatusReg) else '1'; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process (dev_adr, cs0_n) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then case dev_adr(19 downto 17) is when SuperIoRange => sio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => int_ctrl_rd_n <= '0'; when IoIntStatReg => io_int_stat_rd_n <= '0'; when RstCtrlReg => rst_ctrl_rd_n <= '0'; when AtcStatusReg => atc_stat_rd_n <= '0'; when MgmtStatusReg => mgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; else null; end if; end process decoder; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); cs0_n: in std_logic; sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; signal Lsio_dec_n: std_logic; signal Lrst_ctrl_rd_n: std_logic; signal Latc_stat_rd_n: std_logic; signal Lmgmt_stat_rd_n: std_logic; signal Lio_int_stat_rd_n: std_logic; signal Lint_ctrl_rd_n: std_logic; begin decoder: process (dev_adr) begin -- Set defaults for outputs - for synthesis reasons. Lsio_dec_n <= '1'; Lint_ctrl_rd_n <= '1'; Lio_int_stat_rd_n <= '1'; Lrst_ctrl_rd_n <= '1'; Latc_stat_rd_n <= '1'; Lmgmt_stat_rd_n <= '1'; case dev_adr(19 downto 17) is when SuperIoRange => Lsio_dec_n <= '0'; when CtrlRegRange => case dev_adr(16 downto 0) is when IntCtrlReg => Lint_ctrl_rd_n <= '0'; when IoIntStatReg => Lio_int_stat_rd_n <= '0'; when RstCtrlReg => Lrst_ctrl_rd_n <= '0'; when AtcStatusReg => Latc_stat_rd_n <= '0'; when MgmtStatusReg => Lmgmt_stat_rd_n <= '0'; when others => null; end case; when others => null; end case; end process decoder; qualify: process (cs0_n) begin sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if (cs0_n = '0') then sio_dec_n <= Lsio_dec_n; int_ctrl_rd_n <= Lint_ctrl_rd_n; io_int_stat_rd_n <= Lio_int_stat_rd_n; rst_ctrl_rd_n <= Lrst_ctrl_rd_n; atc_stat_rd_n <= Latc_stat_rd_n; mgmt_stat_rd_n <= Lmgmt_stat_rd_n; else null; end if; end process qualify; end synthesis; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n: out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin decoder: process ( dev_adr) begin -- Set defaults for outputs - for synthesis reasons. sio_dec_n <= '1'; int_ctrl_rd_n <= '1'; io_int_stat_rd_n <= '1'; rst_ctrl_rd_n <= '1'; atc_stat_rd_n <= '1'; mgmt_stat_rd_n <= '1'; if dev_adr(19 downto 17) = SuperIOrange then sio_dec_n <= '0'; elsif dev_adr(19 downto 17) = CtrlRegrange then if dev_adr(16 downto 0) = IntCtrlReg then int_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0)= IoIntStatReg then io_int_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = RstCtrlReg then rst_ctrl_rd_n <= '0'; elsif dev_adr(16 downto 0) = AtcStatusReg then atc_stat_rd_n <= '0'; elsif dev_adr(16 downto 0) = MgmtStatusReg then mgmt_stat_rd_n <= '0'; else null; end if; else null; end if; end process decoder; end synthesis; library IEEE; use IEEE.std_logic_1164.all; package decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ); end decProcs; package body decProcs is procedure DEC2x4 (inputs : in std_logic_vector(1 downto 0); decode: out std_logic_vector(3 downto 0) ) is begin case inputs is when "11" => decode := "1000"; when "10" => decode := "0100"; when "01" => decode := "0010"; when "00" => decode := "0001"; when others => decode := "0001"; end case; end DEC2x4; end decProcs; library ieee; use ieee.std_logic_1164.all; entity isa_dec is port ( dev_adr: in std_logic_vector(19 downto 0); sio_dec_n: out std_logic; rst_ctrl_rd_n: out std_logic; atc_stat_rd_n: out std_logic; mgmt_stat_rd_n: out std_logic; io_int_stat_rd_n:out std_logic; int_ctrl_rd_n: out std_logic ); end isa_dec; architecture synthesis of isa_dec is constant CtrlRegRange: std_logic_vector(2 downto 0) := "100"; constant SuperIoRange: std_logic_vector(2 downto 0) := "010"; constant IntCtrlReg: std_logic_vector(16 downto 0) := "00000000000000000"; constant IoIntStatReg: std_logic_vector(16 downto 0) := "00000000000000001"; constant RstCtrlReg: std_logic_vector(16 downto 0) := "00000000000000010"; constant AtcStatusReg: std_logic_vector(16 downto 0) := "00000000000000011"; constant MgmtStatusReg:std_logic_vector(16 downto 0) := "00000000000000100"; begin with dev_adr(19 downto 17) select sio_dec_n <= '0' when SuperIORange, '1' when others; with dev_adr(19 downto 0) select int_ctrl_rd_n <= '0' when CtrlRegRange & IntCtrlReg, '1' when others; with dev_adr(19 downto 0) select io_int_stat_rd_n <= '0' when CtrlRegRange & IoIntStatReg, '1' when others; with dev_adr(19 downto 0) select rst_ctrl_rd_n <= '0' when CtrlRegRange & RstCtrlReg, '1' when others; with dev_adr(19 downto 0) select atc_stat_rd_n <= '0' when CtrlRegRange & AtcStatusReg, '1' when others; with dev_adr(19 downto 0) select mgmt_stat_rd_n <= '0' when CtrlRegRange & MgmtStatusReg, '1' when others; end synthesis; -- Incorporates Errata 5.1 and 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal delayCnt, pulseCnt: unsigned(7 downto 0); signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; begin delayReg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadLength = '1' then -- changed loadLength to loadDelay (Errata 5.1) pulseCntVal <= unsigned(data); end if; end if; end process; pulseDelay: process (clk, reset) begin if (reset = '1') then delayCnt <= "11111111"; elsif(clk'event and clk = '1') then if (loadDelay = '1' or loadLength = '1' or endPulse = '1') then -- changed startPulse to endPulse (Errata 5.1) delayCnt <= delayCntVal; elsif endPulse = '1' then delayCnt <= delayCnt - 1; end if; end if; end process; startPulse <= '1' when delayCnt = "00000000" else '0'; pulseLength: process (clk, reset) begin if (reset = '1') then pulseCnt <= "11111111"; elsif (clk'event and clk = '1') then if (loadLength = '1') then pulseCnt <= pulseCntVal; elsif (startPulse = '1' and endPulse = '1') then pulseCnt <= pulseCntVal; elsif (endPulse = '1') then pulseCnt <= pulseCnt; else pulseCnt <= pulseCnt - 1; end if; end if; end process; endPulse <= '1' when pulseCnt = "00000000" else '0'; pulseOutput: process (clk, reset) begin if (reset = '1') then pulse <= '0'; elsif (clk'event and clk = '1') then if (startPulse = '1') then pulse <= '1'; elsif (endPulse = '1') then pulse <= '0'; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst : in std_logic; q: out std_logic; ); end DFF; architecture rtl of DFF is begin process (clk) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, a,b,c) begin if ((a = '1' and b = '1') or c = '1') then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; a,b,c : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is signal localRst: std_logic; begin localRst <= '1' when (( a = '1' and b = '1') or c = '1') else '0'; process (clk, localRst) begin if localRst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; arst: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q <= '0'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; aset : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, aset) begin if aset = '1' then q <= '1'; elsif clk'event and clk = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; arst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk, arst) begin if arst = '1' then q1 <= '0'; q2 <= '1'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; wait on clk; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; en: in std_logic; clk: in std_logic; q: out std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; envector: in std_logic_vector(7 downto 0); q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if envector = "10010111" then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if en = '1' then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (prst = '1') then q <= '1'; elsif (rst = '1') then q <= '0'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity flipFlop is port ( clock, input: in std_logic; ffOut: out std_logic ); end flipFlop; architecture simple of flipFlop is procedure dff (signal clk: in std_logic; signal d: in std_logic; signal q: out std_logic ) is begin if clk'event and clk = '1' then q <= d; end if; end procedure dff; begin dff(clock, input, ffOut); end simple; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; end: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until rising_edge(clk); if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1, d2: in std_logic; clk: in std_logic; srst : in std_logic; q1, q2: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q1 <= '0'; q2 <= '1'; else q1 <= d1; q2 <= d2; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if srst = '1' then q <= '0'; else q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe_sr is port ( d: in std_logic; clk: in std_logic; en: in std_logic; rst,prst: in std_logic; q: out std_logic ); end struct_dffe_sr; use work.primitive.all; architecture instance of struct_dffe_sr is begin ff: dffe_sr port map ( d => d, clk => clk, en => en, rst => rst, prst => prst, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; srst : in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin if clk'event and clk = '1' then if srst = '1' then q <= '0'; else q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dffe is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end struct_dffe; use work.primitive.all; architecture instance of struct_dffe is begin ff: dffe port map ( d => d, clk => clk, en => en, q => q ); end instance; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity dffTri is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end dffTri; architecture parameterize of dffTri is type tribufType is record ip: std_logic; oe: std_logic; op: std_logic; end record; type tribufArrayType is array (integer range <>) of tribufType; signal tri: tribufArrayType(size - 1 downto 0); begin g0: for i in 0 to size - 1 generate u1: DFFE port map (data(i), tri(i).ip, ff_enable, clock); end generate; g1: for i in 0 to size - 1 generate u2: TRIBUF port map (tri(i).ip, tri(i).oe, tri(i).op); tri(i).oe <= op_enable; qout(i) <= tri(i).op; end generate; end parameterize; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; en: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic bus ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is signal qLocal: std_logic; begin qLocal <= d when en = '1' else qLocal; q <= qLocal; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en, d) begin if en = '1' then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity struct_dlatch is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end struct_dlatch; use work.primitive.all; architecture instance of struct_dlatch is begin latch: dlatchh port map ( d => d, en => en, q => q ); end instance; -- Incorporates Errata 5.4 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity downCounter is port ( clk: in std_logic; reset: in std_logic; count: out std_logic_vector(3 downto 0) ); end downCounter; architecture simple of downCounter is signal countL: unsigned(3 downto 0); signal termCnt: std_logic; begin decrement: process (clk, reset) begin if (reset = '1') then countL <= "1011"; -- Reset to 11 termCnt <= '1'; elsif(clk'event and clk = '1') then if (termCnt = '1') then countL <= "1011"; -- Count rolls over to 11 else countL <= countL - 1; end if; if (countL = "0001") then -- Terminal count decoded 1 cycle earlier termCnt <= '1'; else termCnt <= '0'; end if; end if; end process; count <= std_logic_vector(countL); end simple; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity compareDC is port ( addressBus: in std_logic_vector(31 downto 0); addressHit: out std_logic ); end compareDC; architecture wontWork of compareDC is begin compare: process(addressBus) begin if (addressBus = "011110101011--------------------") then addressHit <= '1'; else addressHit <= '0'; end if; end process compare; end wontWork; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin encode: process (invec) begin case invec is when "00000001" => enc_out <= "000"; when "00000010" => enc_out <= "001"; when "00000100" => enc_out <= "010"; when "00001000" => enc_out <= "011"; when "00010000" => enc_out <= "100"; when "00100000" => enc_out <= "101"; when "01000000" => enc_out <= "110"; when "10000000" => enc_out <= "111"; when others => enc_out <= "000"; end case; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec:in std_logic_vector(7 downto 0); enc_out:out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin process (invec) begin if invec(7) = '1' then enc_out <= "111"; elsif invec(6) = '1' then enc_out <= "110"; elsif invec(5) = '1' then enc_out <= "101"; elsif invec(4) = '1' then enc_out <= "100"; elsif invec(3) = '1' then enc_out <= "011"; elsif invec(2) = '1' then enc_out <= "010"; elsif invec(1) = '1' then enc_out <= "001"; elsif invec(0) = '1' then enc_out <= "000"; else enc_out <= "000"; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity encoder is port (invec: in std_logic_vector(7 downto 0); enc_out: out std_logic_vector(2 downto 0) ); end encoder; architecture rtl of encoder is begin enc_out <= "111" when invec(7) = '1' else "110" when invec(6) = '1' else "101" when invec(5) = '1' else "100" when invec(4) = '1' else "011" when invec(3) = '1' else "010" when invec(2) = '1' else "001" when invec(1) = '1' else "000" when invec(0) = '1' else "000"; end rtl; -- includes Errata 5.2 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; -- errata 5.2 entity compare is port ( ina: in std_logic_vector (3 downto 0); inb: in std_logic_vector (2 downto 0); equal: out std_logic ); end compare; architecture simple of compare is begin equalProc: process (ina, inb) begin if (ina = inb ) then equal <= '1'; else equal <= '0'; end if; end process; end simple; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture behavioral of LogicFcn is begin fcn: process (A,B,C) begin if (A = '0' and B = '0') then Y <= '1'; elsif C = '1' then Y <= '1'; else Y <= '0'; end if; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture dataflow of LogicFcn is begin Y <= '1' when (A = '0' AND B = '0') OR (C = '1') else '0'; end dataflow; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity LogicFcn is port ( A: in std_logic; B: in std_logic; C: in std_logic; Y: out std_logic ); end LogicFcn; architecture structural of LogicFcn is signal notA, notB, andSignal: std_logic; begin i1: inverter port map (i => A, o => notA); i2: inverter port map (i => B, o => notB); a1: and2 port map (i1 => notA, i2 => notB, y => andSignal); o1: or2 port map (i1 => andSignal, i2 => C, y => Y); end structural; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is port ( D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is constant tCQ: time := 8 ns; constant tS: time := 4 ns; constant tH: time := 3 ns; begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process (clk) begin wait until clk = '1'; q <= d; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d: in std_logic; clk: in std_logic; q: out std_logic ); end DFF; architecture rtl of DFF is begin process begin wait until clk = '1'; q <= d; wait on clk; end process; end rtl; configuration SimpleGatesCfg of FEWGATES is for structural for all: AND2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; configuration SimpleGatesCfg of FEWGATES is for structural for u1: and2 use entity work.and2(rtl); end for; for u2: and2 use entity work.and2(rtl); end for; for u3: inverter use entity work.inverter(rtl); end for; for u4: or2 use entity work.or2(rtl); end for; end for; end SimpleGatesCfg; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.and2; use work.or2; use work.inverter; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; -- Configution specifications for all: and2 use entity work.and2(rtl); for u3: inverter use entity work.inverter(rtl); for u4: or2 use entity work.or2(rtl); begin u1: and2 port map (i1 => a, i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; use work.GatesPkg.all; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture concurrent of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin a_and_b <= '1' when a = '1' and b = '1' else '0'; c_and_d <= '1' when c = '1' and d = '1' else '0'; not_c_and_d <= not c_and_d; y <= '1' when a_and_b = '1' or not_c_and_d = '1' else '0'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; package GatesPkg is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; end GatesPkg; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 =>c, i2 => d, y => c_and_d ); u3: inverter port map (a => c_and_d, y => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity FEWGATES is port ( a,b,c,d: in std_logic; y: out std_logic ); end FEWGATES; architecture structural of FEWGATES is component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; signal a_and_b, c_and_d, not_c_and_d: std_logic; begin u1: and2 port map (i1 => a , i2 => b, y => a_and_b ); u2: and2 port map (i1 => c, i2 => d, y => c_and_d ); u3: inverter port map (i => c_and_d, o => not_c_and_d); u4: or2 port map (i1 => a_and_b, i2 => not_c_and_d, y => y ); end structural; library IEEE; use IEEE.std_logic_1164.all; use work.simPrimitives.all; entity simHierarchy is port ( A, B, Clk: in std_logic; Y: out std_logic ); end simHierarchy; architecture hierarchical of simHierarchy is signal ADly, BDly, OrGateDly, ClkDly: std_logic; signal OrGate, FlopOut: std_logic; begin ADly <= transport A after 2 ns; BDly <= transport B after 2 ns; OrGateDly <= transport OrGate after 1.5 ns; ClkDly <= transport Clk after 1 ns; u1: OR2 generic map (tPD => 10 ns) port map ( I1 => ADly, I2 => BDly, Y => OrGate ); u2: simDFF generic map ( tS => 4 ns, tH => 3 ns, tCQ => 8 ns ) port map ( D => OrGateDly, Clk => ClkDly, Q => FlopOut ); Y <= transport FlopOut after 2 ns; end hierarchical; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; -------------------------------------------------------------------------------- --| File name : $RCSfile: io1164.vhd $ --| Library : SUPPORT --| Revision : $Revision: 1.1 $ --| Author(s) : Vantage Analysis Systems, Inc; Des Young --| Integration : Des Young --| Creation : Nov 1995 --| Status : $State: Exp $ --| --| Purpose : IO routines for std_logic_1164. --| Assumptions : Numbers use radixed character set with no prefix. --| Limitations : Does not read VHDL pound-radixed numbers. --| Known Errors: none --| --| Description: --| This is a modified library. The source is basically that donated by --| Vantage to libutil. Des Young removed std_ulogic_vector support (to --| conform to synthesizable libraries), and added read_oct/hex to integer. --| --| ======================================================================= --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights --| reserved. This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package VHDL source --| Package Name: somelib.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : * Overloads procedures READ and WRITE for STD_LOGIC types --| in manner consistent with TEXTIO package. --| * Provides procedures to read and write logic values as --| binary, octal, or hexadecimal values ('X' as appropriate). --| These should be particularly useful for models --| to read in stimulus as 0/1/x or octal or hex. --| Subprograms : --| Notes : --| History : 1. Donated to libutil by Dave Bernstein 15 Jun 94 --| 2. Removed all std_ulogic_vector support, Des Young, 14 Nov 95 --| (This is because that type is not supported for synthesis). --| 3. Added read_oct/hex to integer, Des Young, 20 Nov 95 --| --| ======================================================================= --| Extra routines by Des Young, [email protected]. 1995. GNU copyright. --| ======================================================================= --| -------------------------------------------------------------------------------- library ieee; package io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- import std_logic package use ieee.std_logic_1164.all; -- import textio package use std.textio.all; -- -- the READ and WRITE procedures act similarly to the procedures in the -- STD.TEXTIO package. for each type, there are two read procedures and -- one write procedure for converting between character and internal -- representations of values. each value is represented as the string of -- characters that you would use in VHDL code. (remember that apostrophes -- and quotation marks are not used.) input is case-insensitive. output -- is in upper case. see the following LRM sections for more information: -- -- 2.3 - Subprogram Overloading -- 3.3 - Access Types (STD.TEXTIO.LINE is an access type) -- 7.3.6 - Allocators (allocators create access values) -- 14.3 - Package TEXTIO -- -- Note that the procedures for std_ulogic will match calls with the value -- parameter of type std_logic. -- -- declare READ procedures to overload like in TEXTIO -- procedure read(l: inout line; value: out std_ulogic ; good: out boolean); procedure read(l: inout line; value: out std_ulogic ); procedure read(l: inout line; value: out std_logic_vector ; good: out boolean); procedure read(l: inout line; value: out std_logic_vector ); -- -- declare WRITE procedures to overload like in TEXTIO -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ); procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ); -- -- declare procedures to convert between logic values and octal -- or hexadecimal ('X' where appropriate). -- -- octal / std_logic_vector procedure read_oct (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_oct (l : inout line ; value : out std_logic_vector ); procedure write_oct(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- hexadecimal / std_logic_vector procedure read_hex (l : inout line ; value : out std_logic_vector ; good : out boolean ); procedure read_hex (l : inout line ; value : out std_logic_vector ); procedure write_hex(l : inout line ; value : in std_logic_vector ; justified : in side := right; field : in width := 0 ); -- read a number into an integer procedure read_oct(l : inout line; value : out integer; good : out boolean); procedure read_oct(l : inout line; value : out integer); procedure read_hex(l : inout line; value : out integer; good : out boolean); procedure read_hex(l : inout line; value : out integer); end io1164; -------------------------------------------------------------------------------- --| Copyright (c) 1992-1994 Vantage Analysis Systems, Inc., all rights reserved --| This package is provided by Vantage Analysis Systems. --| The package may not be sold without the express written consent of --| Vantage Analysis Systems, Inc. --| --| The VHDL for this package may be copied and/or distributed as long as --| this copyright notice is retained in the source and any modifications --| are clearly marked in the History: list. --| --| Title : IO1164 package body VHDL source --| Package Name: VANTAGE_LOGIC.IO1164 --| File Name : io1164.vhdl --| Author(s) : dbb --| Purpose : source for IO1164 package body --| Subprograms : --| Notes : see package declaration --| History : see package declaration -------------------------------------------------------------------------------- package body io1164 is --$ !VANTAGE_METACOMMENTS_ON --$ !VANTAGE_DNA_ON -- define lowercase conversion of characters for canonical comparison type char2char_t is array (character'low to character'high) of character; constant lowcase: char2char_t := ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb, can, em, sub, esc, fsp, gsp, rsp, usp, ' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', del); -- define conversions between various types -- logic -> character type f_logic_to_character_t is array (std_ulogic'low to std_ulogic'high) of character; constant f_logic_to_character : f_logic_to_character_t := ( 'U' => 'U', 'X' => 'X', '0' => '0', '1' => '1', 'Z' => 'Z', 'W' => 'W', 'L' => 'L', 'H' => 'H', '-' => '-' ); -- character, integer, logic constant x_charcode : integer := -1; constant maxoct_charcode: integer := 7; constant maxhex_charcode: integer := 15; constant bad_charcode : integer := integer'left; type digit2int_t is array ( character'low to character'high ) of integer; constant octdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, 'X' | 'x' => x_charcode, others => bad_charcode ); constant hexdigit2int: digit2int_t := ( '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' | 'a' => 10, 'B' | 'b' => 11, 'C' | 'c' => 12, 'D' | 'd' => 13, 'E' | 'e' => 14, 'F' | 'f' => 15, 'X' | 'x' => x_charcode, others => bad_charcode ); constant oct_bits_per_digit: integer := 3; constant hex_bits_per_digit: integer := 4; type int2octdigit_t is array ( 0 to maxoct_charcode ) of character; constant int2octdigit: int2octdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7' ); type int2hexdigit_t is array ( 0 to maxhex_charcode ) of character; constant int2hexdigit: int2hexdigit_t := ( 0 => '0', 1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5', 6 => '6', 7 => '7', 8 => '8', 9 => '9', 10 => 'A', 11 => 'B', 12 => 'C', 13 => 'D', 14 => 'E', 15 => 'F' ); type oct_logic_vector_t is array(1 to oct_bits_per_digit) of std_ulogic; type octint2logic_t is array (x_charcode to maxoct_charcode) of oct_logic_vector_t; constant octint2logic : octint2logic_t := ( ( 'X', 'X', 'X' ), ( '0', '0', '0' ), ( '0', '0', '1' ), ( '0', '1', '0' ), ( '0', '1', '1' ), ( '1', '0', '0' ), ( '1', '0', '1' ), ( '1', '1', '0' ), ( '1', '1', '1' ) ); type hex_logic_vector_t is array(1 to hex_bits_per_digit) of std_ulogic; type hexint2logic_t is array (x_charcode to maxhex_charcode) of hex_logic_vector_t; constant hexint2logic : hexint2logic_t := ( ( 'X', 'X', 'X', 'X' ), ( '0', '0', '0', '0' ), ( '0', '0', '0', '1' ), ( '0', '0', '1', '0' ), ( '0', '0', '1', '1' ), ( '0', '1', '0', '0' ), ( '0', '1', '0', '1' ), ( '0', '1', '1', '0' ), ( '0', '1', '1', '1' ), ( '1', '0', '0', '0' ), ( '1', '0', '0', '1' ), ( '1', '0', '1', '0' ), ( '1', '0', '1', '1' ), ( '1', '1', '0', '0' ), ( '1', '1', '0', '1' ), ( '1', '1', '1', '0' ), ( '1', '1', '1', '1' ) ); ---------------------------------------------------------------------------- -- READ procedure bodies -- -- The strategy for duplicating TEXTIO's overloading of procedures -- with and without GOOD parameters is to put all the logic in the -- version with the GOOD parameter and to have the version without -- GOOD approximate a runtime error by use of an assertion. -- ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure read( l: inout line; value: out std_ulogic; good : out boolean ) is variable c : character; -- char read while looping variable m : line; -- safe copy of L variable success: boolean := false; -- readable version of GOOD variable done : boolean := false; -- flag to say done reading chars begin -- -- algorithm: -- -- if there are characters in the line -- save a copy of the line -- get the next character -- if got one -- set value -- if all ok -- free temp copy -- else -- free passed in line -- assign copy back to line -- set GOOD -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- grab the next character read( l, c, success ); -- if read ok if success then -- -- an issue here is whether lower-case values should be accepted or not -- -- determine the value case c is when 'U' | 'u' => value := 'U'; when 'X' | 'x' => value := 'X'; when '0' => value := '0'; when '1' => value := '1'; when 'Z' | 'z' => value := 'Z'; when 'W' | 'w' => value := 'W'; when 'L' | 'l' => value := 'L'; when 'H' | 'h' => value := 'H'; when '-' => value := '-'; when others => success := false; end case; end if; -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; end if; -- non null access, non empty string -- set output parameter good := success; end read; procedure read( l: inout line; value: out std_ulogic ) is variable success: boolean; -- internal good flag begin read( l, value, success ); -- use safe version assert success report "IO1164.READ: Unable to read STD_ULOGIC value." severity error; end read; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure read(l : inout line ; value: out std_logic_vector; good : out boolean ) is variable m : line ; -- saved copy of L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- value for one array element variable c : character ; -- read a character begin -- -- algorithm: -- -- this procedure strips off leading whitespace, and then calls the -- READ procedure for each single logic value element in the output -- array. -- -- only operate on lines that contain characters if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save a copy of string in case read fails m := new string'( l.all ); -- loop for each element in output array for i in value'range loop -- prohibit internal blanks if i /= value'left then if l.all'length = 0 then success := false; exit; end if; c := l.all(l.all'left); if c = ' ' or c = ht then success := false; exit; end if; end if; -- read the next logic value read( l, logic_value, success ); -- stuff the value in if ok, else bail out if success then value( i ) := logic_value; else exit; end if; end loop; -- each element in output array -- free working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; elsif ( value'length /= 0 ) then -- string is empty but the return array has 1+ elements success := false; end if; -- set output parameter good := success; end read; procedure read(l: inout line; value: out std_logic_vector ) is variable success: boolean; begin read( l, value, success ); assert success report "IO1164.READ: Unable to read T_WLOGIC_VECTOR value." severity error; end read; ---------------------------------------------------------------------------- -- WRITE procedure bodies ---------------------------------------------------------------------------- -- -- std_ulogic -- note: compatible with std_logic -- procedure write(l : inout line ; value : in std_ulogic ; justified: in side := right; field : in width := 0 ) is begin -- -- algorithm: -- -- just write out the string associated with the enumerated -- value. -- case value is when 'U' => write( l, character'('U'), justified, field ); when 'X' => write( l, character'('X'), justified, field ); when '0' => write( l, character'('0'), justified, field ); when '1' => write( l, character'('1'), justified, field ); when 'Z' => write( l, character'('Z'), justified, field ); when 'W' => write( l, character'('W'), justified, field ); when 'L' => write( l, character'('L'), justified, field ); when 'H' => write( l, character'('H'), justified, field ); when '-' => write( l, character'('-'), justified, field ); end case; end write; -- -- std_logic_vector -- note: NOT compatible with std_ulogic_vector -- procedure write(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m: line; -- build up intermediate string begin -- -- algorithm: -- -- for each value in array -- add string representing value to intermediate string -- write intermediate string to line parameter -- free intermediate string -- -- for each value in array for i in value'range loop -- add string representing value to intermediate string write( m, value( i ) ); end loop; -- write intermediate string to line parameter write( l, m.all, justified, field ); -- free intermediate string deallocate( m ); end write; -------------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- procedure bodies for octal and hexadecimal read and write ---------------------------------------------------------------------------- -- -- std_logic_vector/octal -- note: NOT compatible with std_ulogic_vector -- procedure read_oct(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable oct_logic_vector: oct_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem oct_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := octdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array oct_logic_vector := octint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := oct_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = oct_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := octdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array oct_logic_vector := octint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_oct; procedure read_oct(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read T_LOGIC_VECTOR value." severity error; end read_oct; procedure write_oct(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem oct_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_OCT: VALUE'Length is not a multiple of 3." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / oct_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = oct_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2octdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_oct; -- -- std_logic_vector/hexadecimal -- note: NOT compatible with std_ulogic_vector -- procedure read_hex(l : inout line ; value : out std_logic_vector; good : out boolean ) is variable m : line ; -- safe L variable success : boolean := true; -- readable GOOD variable logic_value : std_logic ; -- elem value variable c : character ; -- char read variable charcode : integer ; -- char->int variable hex_logic_vector: hex_logic_vector_t ; -- for 1 digit variable bitpos : integer ; -- in state vec. begin -- -- algorithm: -- -- skip over leading blanks, then read a digit -- and do a conversion into a logic value -- for each element in array -- -- make sure logic array is right size to read this base success := ( ( value'length rem hex_bits_per_digit ) = 0 ); if success then -- only operate on non-empty strings if ( ( l /= null ) and ( l.all'length /= 0 ) ) then -- save old copy of string in case read fails m := new string'( l.all ); -- pick off leading white space and get first significant char c := ' '; while success and ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = ht ) ) loop read( l, c, success ); end loop; -- turn character into integer charcode := hexdigit2int( c ); -- not doing any bits yet bitpos := 0; -- check for bad first character if charcode = bad_charcode then success := false; else -- loop through each value in array hex_logic_vector := hexint2logic( charcode ); for i in value'range loop -- doing the next bit bitpos := bitpos + 1; -- stick the value in value( i ) := hex_logic_vector( bitpos ); -- read the next character if we're not at array end if ( bitpos = hex_bits_per_digit ) and ( i /= value'right ) then read( l, c, success ); if not success then exit; end if; -- turn character into integer charcode := hexdigit2int( c ); -- check for bad char if charcode = bad_charcode then success := false; exit; end if; -- reset bit position bitpos := 0; -- turn character code into state array hex_logic_vector := hexint2logic( charcode ); end if; end loop; -- each index in return array end if; -- if bad first character -- clean up working storage if success then deallocate( m ); else deallocate( l ); l := m; end if; -- no characters to read for return array that isn't null slice elsif ( value'length /= 0 ) then success := false; end if; -- non null access, non empty string end if; -- set out parameter of success good := success; end read_hex; procedure read_hex(l : inout line ; value : out std_logic_vector) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read T_LOGIC_VECTOR value." severity error; end read_hex; procedure write_hex(l : inout line ; value : in std_logic_vector ; justified: in side := right; field : in width := 0 ) is variable m : line ; -- safe copy of L variable goodlength : boolean ; -- array is ok len for this base variable isx : boolean ; -- an X in this digit variable integer_value: integer ; -- accumulate integer value variable c : character; -- character read variable charpos : integer ; -- index string being contructed variable bitpos : integer ; -- bit index inside digit begin -- -- algorithm: -- -- make sure this array can be written in this base -- create a string to place intermediate results -- initialize counters and flags to beginning of string -- for each item in array -- note unknown, else accumulate logic into integer -- if at this digit's last bit -- stuff digit just computed into intermediate result -- reset flags and counters except for charpos -- write intermediate result into line -- free work storage -- -- make sure this array can be written in this base goodlength := ( ( value'length rem hex_bits_per_digit ) = 0 ); assert goodlength report "IO1164.WRITE_HEX: VALUE'Length is not a multiple of 4." severity error; if goodlength then -- create a string to place intermediate results m := new string(1 to ( value'length / hex_bits_per_digit ) ); -- initialize counters and flags to beginning of string charpos := 0; bitpos := 0; isx := false; integer_value := 0; -- for each item in array for i in value'range loop -- note unknown, else accumulate logic into integer case value(i) is when '0' | 'L' => integer_value := integer_value * 2; when '1' | 'H' => integer_value := ( integer_value * 2 ) + 1; when others => isx := true; end case; -- see if we've done this digit's last bit bitpos := bitpos + 1; if bitpos = hex_bits_per_digit then -- stuff the digit just computed into the intermediate result charpos := charpos + 1; if isx then m.all(charpos) := 'X'; else m.all(charpos) := int2hexdigit( integer_value ); end if; -- reset flags and counters except for location in string being constructed bitpos := 0; isx := false; integer_value := 0; end if; end loop; -- write intermediate result into line write( l, m.all, justified, field ); -- free work storage deallocate( m ); end if; end write_hex; ------------------------------------------------------------------------------ ------------------------------------ -- Read octal/hex numbers to integer ------------------------------------ -- -- Read octal to integer -- procedure read_oct(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := octdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := octdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 8) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_oct; -- simple version procedure read_oct(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_oct( l, value, success ); -- use safe version assert success report "IO1164.READ_OCT: Unable to read octal integer value." severity error; end read_oct; -- -- Read hex to integer -- procedure read_hex(l : inout line; value : out integer; good : out boolean) is variable pos : integer; variable digit : integer; variable result : integer := 0; variable success : boolean := true; variable c : character; variable old_l : line := l; begin -- algorithm: -- -- skip leading white space, read digit, convert -- into integer -- if (l /= NULL) then -- set pos to start of actual number by skipping white space pos := l'LEFT; c := l(pos); while ( l.all'length > 0 ) and ( ( c = ' ' ) or ( c = HT ) ) loop pos := pos + 1; c := l(pos); end loop; -- check for start of valid number digit := hexdigit2int(l(pos)); if ((digit = bad_charcode) or (digit = x_charcode)) then good := FALSE; return; else -- calculate integer value for i in pos to l'RIGHT loop digit := hexdigit2int(l(pos)); exit when (digit = bad_charcode) or (digit = x_charcode); result := (result * 16) + digit; pos := pos + 1; end loop; value := result; -- shrink line if (pos > 1) then l := new string'(old_l(pos to old_l'HIGH)); deallocate(old_l); end if; good := TRUE; return; end if; else good := FALSE; end if; end read_hex; -- simple version procedure read_hex(l : inout line; value : out integer) is variable success: boolean; -- internal good flag begin read_hex( l, value, success ); -- use safe version assert success report "IO1164.READ_HEX: Unable to read hex integer value." severity error; end read_hex; end io1164; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity asyncLdCnt is port ( loadVal: in std_logic_vector(3 downto 0); clk, load: in std_logic; q: out std_logic_vector(3 downto 0) ); end asyncLdCnt; architecture rtl of asyncLdCnt is signal qLocal: unsigned(3 downto 0); begin process (clk, load, loadVal) begin if (load = '1') then qLocal <= to_unsigned(loadVal); elsif (clk'event and clk = '1' ) then qLocal <= qLocal + 1; end if; end process; q <= to_stdlogicvector(qLocal); end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity LoadCnt is port ( CntEn: in std_logic; LdCnt: in std_logic; LdData: in std_logic_vector(3 downto 0); Clk: in std_logic; Rst: in std_logic; CntVal: out std_logic_vector(3 downto 0) ); end LoadCnt; architecture behavioral of LoadCnt is signal Cnt: std_logic_vector(3 downto 0); begin counter: process (Clk, Rst) begin if Rst = '1' then Cnt <= (others => '0'); elsif (Clk'event and Clk = '1') then if (LdCnt = '1') then Cnt <= LdData; elsif (CntEn = '1') then Cnt <= Cnt + 1; else Cnt <= Cnt; end if; end if; end process; CntVal <= Cnt; end behavioral; library IEEE; use IEEE.std_logic_1164.all; library UTILS; use UTILS.io1164.all; use std.textio.all; entity loadCntTB is end loadCntTB; architecture testbench of loadCntTB is component loadCnt port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end component; file vectorFile: text is in "vectorfile"; type vectorType is record data: std_logic_vector(7 downto 0); load: std_logic; rst: std_logic; q: std_logic_vector(7 downto 0); end record; signal testVector: vectorType; signal TestClk: std_logic := '0'; signal Qout: std_logic_vector(7 downto 0); constant ClkPeriod: time := 100 ns; for all: loadCnt use entity work.loadcnt(rtl); begin -- File reading and stimulus application readVec: process variable VectorLine: line; variable VectorValid: boolean; variable vRst: std_logic; variable vLoad: std_logic; variable vData: std_logic_vector(7 downto 0); variable vQ: std_logic_vector(7 downto 0); begin while not endfile (vectorFile) loop readline(vectorFile, VectorLine); read(VectorLine, vRst, good => VectorValid); next when not VectorValid; read(VectorLine, vLoad); read(VectorLine, vData); read(VectorLine, vQ); wait for ClkPeriod/4; testVector.Rst <= vRst; testVector.Load <= vLoad; testVector.Data <= vData; testVector.Q <= vQ; wait for (ClkPeriod/4) * 3; end loop; assert false report "Simulation complete" severity note; wait; end process; -- Free running test clock TestClk <= not TestClk after ClkPeriod/2; -- Instance of design being tested u1: loadCnt port map (Data => testVector.Data, load => testVector.Load, clk => TestClk, rst => testVector.Rst, q => Qout ); -- Process to verify outputs verify: process (TestClk) variable ErrorMsg: line; begin if (TestClk'event and TestClk = '0') then if Qout /= testVector.Q then write(ErrorMsg, string'("Vector failed ")); write(ErrorMsg, now); writeline(output, ErrorMsg); end if; end if; end process; end testbench; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity loadCnt is port ( data: in std_logic_vector (7 downto 0); load: in std_logic; clk: in std_logic; rst: in std_logic; q: out std_logic_vector (7 downto 0) ); end loadCnt; architecture rtl of loadCnt is signal cnt: std_logic_vector (7 downto 0); begin counter: process (clk, rst) begin if (rst = '1') then cnt <= (others => '0'); elsif (clk'event and clk = '1') then if (load = '1') then cnt <= data; else cnt <= cnt + 1; end if; end if; end process; q <= cnt; end rtl; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity multiplier is port ( a,b : in std_logic_vector (15 downto 0); product: out std_logic_vector (31 downto 0) ); end multiplier; architecture dataflow of multiplier is begin product <= a * b; end dataflow; library IEEE; use IEEE.std_logic_1164.all; entity mux is port ( A, B, Sel: in std_logic; Y: out std_logic ); end mux; architecture simModel of mux is -- Delay Constants constant tPD_A: time := 10 ns; constant tPD_B: time := 15 ns; constant tPD_Sel: time := 5 ns; begin DelayMux: process (A, B, Sel) variable localY: std_logic; -- Zero delay place holder for Y begin -- Zero delay model case Sel is when '0' => localY := A; when others => localY := B; end case; -- Delay calculation if (B'event) then Y <= localY after tPD_B; elsif (A'event) then Y <= localY after tPD_A; else Y <= localY after tPD_Sel; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) begin if (a + b = "10011010") then result <= c; elsif (a + b = "01011001") then result <= d; elsif (a + b = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture concurrent of TRIBUF8 is begin op <= ip when oe = '1' else (others => 'Z'); end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture concurrent of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end concurrent; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF8 is port ( ip: in std_logic_vector(7 downto 0); oe: in std_logic; op: out std_logic_vector(7 downto 0) ); end TRIBUF8; architecture sequential of TRIBUF8 is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= (others => 'Z'); end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in bit; oe: in bit; op: out bit ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= null; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture sequential of TRIBUF is begin enable: process (ip,oe) begin if (oe = '1') then op <= ip; else op <= 'Z'; end if; end process; end sequential; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity tribuffer is port ( input: in std_logic; enable: in std_logic; output: out std_logic ); end tribuffer; architecture structural of tribuffer is begin u1: tribuf port map (ip => input, oe => enable, op => output ); end structural; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); begin genXOR(0) <= '0'; parTree: for i in 1 to ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; entity oddParityLoop is generic ( width : integer := 8 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityLoop ; architecture scaleable of oddParityLoop is begin process (ad) variable loopXor: std_logic; begin loopXor := '0'; for i in 0 to width -1 loop loopXor := loopXor xor ad( i ) ; end loop ; oddParity <= loopXor ; end process; end scaleable ; library IEEE; use IEEE.std_logic_1164.all; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is port ( I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after 10 ns; end simple; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder is port ( a,b: in std_logic_vector(3 downto 0); sum: out std_logic_vector(3 downto 0); overflow: out std_logic ); end adder; architecture concat of adder is signal localSum: std_logic_vector(4 downto 0); begin localSum <= std_logic_vector(unsigned('0' & a) + unsigned('0' & b)); sum <= localSum(3 downto 0); overflow <= localSum(4); end concat; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity paramDFF is generic (size: integer := 8); port ( data: in std_logic_vector(size - 1 downto 0); clock: in std_logic; reset: in std_logic; ff_enable: in std_logic; op_enable: in std_logic; qout: out std_logic_vector(size - 1 downto 0) ); end paramDFF; architecture parameterize of paramDFF is signal reg: std_logic_vector(size - 1 downto 0); begin u1: pDFFE generic map (n => size) port map (d => data, clk =>clock, rst => reset, en => ff_enable, q => reg ); u2: pTRIBUF generic map (n => size) port map (ip => reg, oe => op_enable, op => qout ); end paramterize; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal genXor: std_logic_vector(ad'range); signal one: std_logic := '1'; begin parTree: for i in ad'range generate g0: if i = 0 generate x0: xor2 port map (i1 => one, i2 => one, y => genXor(0) ); end generate; g1: if i > 0 and i <= ad'high generate x1: xor2 port map (i1 => genXor(i - 1), i2 => ad(i - 1), y => genXor(i) ); end generate; end generate; oddParity <= genXor(ad'high) ; end scaleable ; library ieee; use ieee.std_logic_1164.all; use work.primitive.all; entity oddParityGen is generic ( width : integer := 32 ); -- (2 <= width <= 32) and a power of 2 port (ad: in std_logic_vector (width - 1 downto 0); oddParity : out std_logic ) ; end oddParityGen; architecture scaleable of oddParityGen is signal stage0: std_logic_vector(31 downto 0); signal stage1: std_logic_vector(15 downto 0); signal stage2: std_logic_vector(7 downto 0); signal stage3: std_logic_vector(3 downto 0); signal stage4: std_logic_vector(1 downto 0); begin g4: for i in stage4'range generate g41: if (ad'length > 2) generate x4: xor2 port map (stage3(i), stage3(i + stage4'length), stage4(i)); end generate; end generate; g3: for i in stage3'range generate g31: if (ad'length > 4) generate x3: xor2 port map (stage2(i), stage2(i + stage3'length), stage3(i)); end generate; end generate; g2: for i in stage2'range generate g21: if (ad'length > 8) generate x2: xor2 port map (stage1(i), stage1(i + stage2'length), stage2(i)); end generate; end generate; g1: for i in stage1'range generate g11: if (ad'length > 16) generate x1: xor2 port map (stage0(i), stage0(i + stage1'length), stage1(i)); end generate; end generate; s1: for i in ad'range generate s14: if (ad'length = 2) generate stage4(i) <= ad(i); end generate; s13: if (ad'length = 4) generate stage3(i) <= ad(i); end generate; s12: if (ad'length = 8) generate stage2(i) <= ad(i); end generate; s11: if (ad'length = 16) generate stage1(i) <= ad(i); end generate; s10: if (ad'length = 32) generate stage0(i) <= ad(i); end generate; end generate; genPar: xor2 port map (stage4(0), stage4(1), oddParity); end scaleable ; library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in unsigned(3 downto 0); power : out unsigned(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; signal inputValInt: integer range 0 to 15; signal powerL: integer range 0 to 65535; begin inputValInt <= to_integer(inputVal); power <= to_unsigned(powerL,16); process begin wait until Clk = '1'; powerL <= Pow(inputValInt,4); end process; end behavioral; package PowerPkg is component Power port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end component; end PowerPkg; use work.bv_math.all; use work.int_math.all; use work.PowerPkg.all; entity Power is port( Clk : in bit; inputVal : in bit_vector(0 to 3); power : out bit_vector(0 to 15) ); end Power; architecture funky of Power is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; Variable i : integer := 0; begin while( i < Exp ) loop Result := Result * N; i := i + 1; end loop; return( Result ); end Pow; function RollVal( CntlVal : integer ) return integer is begin return( Pow( 2, CntlVal ) + 2 ); end RollVal; begin process begin wait until Clk = '1'; power <= i2bv(Rollval(bv2I(inputVal)),16); end process; end funky; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity priority_encoder is port (interrupts : in std_logic_vector(7 downto 0); priority : in std_logic_vector(2 downto 0); result : out std_logic_vector(2 downto 0) ); end priority_encoder; architecture behave of priority_encoder is begin process (interrupts) variable selectIn : integer; variable LoopCount : integer; begin LoopCount := 1; selectIn := to_integer(to_unsigned(priority)); while (LoopCount <= 7) and (interrupts(selectIn) /= '0') loop if (selectIn = 0) then selectIn := 7; else selectIn := selectIn - 1; end if; LoopCount := LoopCount + 1; end loop; result <= std_logic_vector(to_unsigned(selectIn,3)); end process; end behave; library IEEE; use IEEE.std_logic_1164.all; package primitive is component DFFE port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end component; component DFFE_SR port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end component; component DLATCHH port ( d: in std_logic; en: in std_logic; q: out std_logic ); end component; component AND2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component OR2 port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end component; component INVERTER port ( i: in std_logic; o: out std_logic ); end component; component TRIBUF port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end component; component BIDIR port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end component; end package; library IEEE; use IEEE.std_logic_1164.all; entity DFFE is port ( d: in std_logic; q: out std_logic; en: in std_logic; clk: in std_logic ); end DFFE; architecture rtl of DFFE is begin process begin wait until clk = '1'; if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DFFE_SR is port ( d: in std_logic; en: in std_logic; clk: in std_logic; rst: in std_logic; prst: in std_logic; q: out std_logic ); end DFFE_SR; architecture rtl of DFFE_SR is begin process (clk, rst, prst) begin if (rst = '1') then q <= '0'; elsif (prst = '1') then q <= '1'; elsif (clk'event and clk = '1') then if (en = '1') then q <= d; end if; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity DLATCHH is port ( d: in std_logic; en: in std_logic; q: out std_logic ); end DLATCHH; architecture rtl of DLATCHH is begin process (en) begin if (en = '1') then q <= d; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity AND2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end AND2; architecture rtl of AND2 is begin y <= '1' when i1 = '1' and i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity OR2 is port ( i1: in std_logic; i2: in std_logic; y: out std_logic ); end OR2; architecture rtl of OR2 is begin y <= '1' when i1 = '1' or i2 = '1' else '0'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity INVERTER is port ( i: in std_logic; o: out std_logic ); end INVERTER; architecture rtl of INVERTER is begin o <= not i; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity TRIBUF is port ( ip: in std_logic; oe: in std_logic; op: out std_logic ); end TRIBUF; architecture rtl of TRIBUF is begin op <= ip when oe = '1' else 'Z'; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity BIDIR is port ( ip: in std_logic; oe: in std_logic; op_fb: out std_logic; op: inout std_logic ); end BIDIR; architecture rtl of BIDIR is begin op <= ip when oe = '1' else 'Z'; op_fb <= op; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; subtype fsmType is std_logic_vector(1 downto 0); constant loadDelayCnt : fsmType := "00"; constant waitDelayEnd : fsmType := "10"; constant loadLengthCnt : fsmType := "11"; constant waitLengthEnd : fsmType := "01"; signal currState, nextState: fsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; -- Assign pulse output pulse <= currState(0); end rtl; library ieee; use ieee.std_logic_1164.all; entity pulseErr is port (a: in std_logic; b: out std_logic ); end pulseErr; architecture behavior of pulseErr is signal c: std_logic; begin pulse: process (a,c) begin b <= c XOR a; c <= a; end process; end behavior; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulse is port ( clk, reset: in std_logic; loadLength,loadDelay: in std_logic; data: in std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulse; architecture rtl of progPulse is signal downCnt, downCntData: unsigned(7 downto 0); signal downCntLd, downCntEn: std_logic; signal delayCntVal, pulseCntVal: unsigned(7 downto 0); signal startPulse, endPulse: std_logic; type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; begin delayreg: process (clk, reset) begin if reset = '1' then delayCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then delayCntVal <= to_unsigned(data); end if; end if; end process; lengthReg: process (clk, reset) begin if reset = '1' then pulseCntVal <= "11111111"; elsif clk'event and clk = '1' then if loadDelay = '1' then pulseCntVal <= to_unsigned(data); end if; end if; end process; nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCnt = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, pulseCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downCntData <= pulseCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downCntData <= pulseCntVal; pulse <= '0'; end case; end process outConProc; downCntr: process (clk,reset) begin if (reset = '1') then downCnt <= "00000000"; elsif (clk'event and clk = '1') then if (downCntLd = '1') then downCnt <= downCntData; elsif (downCntEn = '1') then downCnt <= downCnt - 1; else downCnt <= downCnt; end if; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); type stateVec is array (3 downto 0) of std_logic; type stateBits is array (progPulseFsmType) of stateVec; signal loadVal: std_logic; constant stateTable: stateBits := ( loadDelayCnt => "0010", waitDelayEnd => "0100", loadLengthCnt => "0011", waitLengthEnd => "1101" ); -- ^^^^ -- ||||__ loadVal -- |||___ downCntLd -- ||____ downCntEn -- |_____ pulse signal currState, nextState: progPulseFsmType; begin nextStProc: process (currState, downCnt, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (to_unsigned(downCnt) = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; pulse <= stateTable(currState)(3); downCntEn <= stateTable(currState)(2); downCntLd <= stateTable(currState)(1); loadVal <= stateTable(currState)(0); downCntData <= delayCntVal when loadVal = '0' else lengthCntVal; end fsm; -- Incorporates Errata 6.1 library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity progPulseFsm is port ( downCnt: in std_logic_vector(7 downto 0); delayCntVal: in std_logic_vector(7 downto 0); lengthCntVal: in std_logic_vector(7 downto 0); loadLength: in std_logic; loadDelay: in std_logic; clk: in std_logic; reset: in std_logic; downCntEn: out std_logic; downCntLd: out std_logic; downtCntData: out std_logic_vector(7 downto 0); pulse: out std_logic ); end progPulseFsm; architecture fsm of progPulseFsm is type progPulseFsmType is (loadDelayCnt, waitDelayEnd, loadLengthCnt, waitLengthEnd); signal currState, nextState: progPulseFsmType; signal downCntL: unsigned (7 downto 0); begin downCntL <= to_unsigned(downCnt); -- convert downCnt to unsigned nextStProc: process (currState, downCntL, loadDelay, loadLength) begin case currState is when loadDelayCnt => nextState <= waitDelayEnd; when waitDelayEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadLengthCnt; else nextState <= waitDelayEnd; end if; when loadLengthCnt => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; else nextState <= waitLengthEnd; end if; when waitLengthEnd => if (loadDelay = '1' or loadLength = '1') then nextState <= loadDelayCnt; elsif (downCntL = 0) then nextState <= loadDelayCnt; else nextState <= waitDelayEnd; end if; when others => null; end case; end process nextStProc; currStProc: process (clk, reset) begin if (reset = '1') then currState <= loadDelayCnt; elsif (clk'event and clk = '1') then currState <= nextState; end if; end process currStProc; outConProc: process (currState, delayCntVal, lengthCntVal) begin case currState is when loadDelayCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; when waitDelayEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= delayCntVal; pulse <= '0'; when loadLengthCnt => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= lengthCntVal; pulse <= '1'; when waitLengthEnd => downCntEn <= '1'; downCntLd <= '0'; downtCntData <= lengthCntVal; pulse <= '1'; when others => downCntEn <= '0'; downCntLd <= '1'; downtCntData <= delayCntVal; pulse <= '0'; end case; end process outConProc; end fsm; -- Incorporates errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use work.specialFunctions.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(unsigned(inputVal)),4),16)); end process; end behavioral; -- Incorporate errata 5.4 library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= std_logic_vector(to_unsigned(Pow(to_integer(to_unsigned(inputVal)),4),16)); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity powerOfFour is port( clk : in std_logic; inputVal : in std_logic_vector(3 downto 0); power : out std_logic_vector(15 downto 0) ); end powerOfFour; architecture behavioral of powerOfFour is function Pow( N, Exp : integer ) return integer is Variable Result : integer := 1; begin for i in 1 to Exp loop Result := Result * N; end loop; return( Result ); end Pow; begin process begin wait until Clk = '1'; power <= conv_std_logic_vector(Pow(conv_integer(inputVal),4),16); end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity regFile is port ( clk, rst: in std_logic; data: in std_logic_vector(31 downto 0); regSel: in std_logic_vector(1 downto 0); wrEnable: in std_logic; regOut: out std_logic_vector(31 downto 0) ); end regFile; architecture behavioral of regFile is subtype reg is std_logic_vector(31 downto 0); type regArray is array (integer range <>) of reg; signal registerFile: regArray(0 to 3); begin regProc: process (clk, rst) variable i: integer; begin i := 0; if rst = '1' then while i <= registerFile'high loop registerFile(i) <= (others => '0'); i := i + 1; end loop; elsif clk'event and clk = '1' then if (wrEnable = '1') then case regSel is when "00" => registerFile(0) <= data; when "01" => registerFile(1) <= data; when "10" => registerFile(2) <= data; when "11" => registerFile(3) <= data; when others => null; end case; end if; end if; end process; outputs: process(regSel, registerFile) begin case regSel is when "00" => regOut <= registerFile(0); when "01" => regOut <= registerFile(1); when "10" => regOut <= registerFile(2); when "11" => regOut <= registerFile(3); when others => null; end case; end process; end behavioral; library IEEE; use IEEE.std_logic_1164.all; entity DFF is port ( d1,d2: in std_logic; q1,q2: out std_logic; clk: in std_logic; rst : in std_logic ); end DFF; architecture rtl of DFF is begin resetLatch: process (clk, rst) begin if rst = '1' then q1 <= '0'; elsif clk'event and clk = '1' then q1 <= d1; q2 <= d2; end if; end process; end rtl; library ieee; use ieee.std_logic_1164.all; entity resFcnDemo is port ( a, b: in std_logic; oeA,oeB: in std_logic; result: out std_logic ); end resFcnDemo; architecture multiDriver of resFcnDemo is begin result <= a when oeA = '1' else 'Z'; result <= b when oeB = '1' else 'Z'; end multiDriver; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleDFF is port ( data: in std_logic_vector(7 downto 0); clock: in std_logic; enable: in std_logic; qout: out std_logic_vector(7 downto 0) ); end scaleDFF; architecture scalable of scaleDFF is begin u1: sDFFE port map (d => data, clk =>clock, en => enable, q => qout ); end scalable; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is signal la_n, lb_n, lc_n, ld_n, le_n, lf_n, lg_n: std_logic; signal oe: std_logic; begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" la_n <= '1'; lb_n <= '1'; lc_n <= '1'; ld_n <= '1'; le_n <= '1'; lf_n <= '1'; lg_n <= '1'; case bcdInputs is when "0000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; when "0001" => lb_n <= '0'; lc_n <= '0'; when "0010" => la_n <= '0'; lb_n <= '0'; ld_n <= '0'; le_n <= '0'; lg_n <= '0'; when "0011" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lg_n <= '0'; when "0100" => lb_n <= '0'; lc_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0101" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0110" => la_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "0111" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; when "1000" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; le_n <= '0'; lf_n <= '0'; lg_n <= '0'; when "1001" => la_n <= '0'; lb_n <= '0'; lc_n <= '0'; ld_n <= '0'; lf_n <= '0'; lg_n <= '0'; -- All other inputs possibilities are "don't care" when others => la_n <= 'X'; lb_n <= 'X'; lc_n <= 'X'; ld_n <= 'X'; le_n <= 'X'; lf_n <= 'X'; lg_n <= 'X'; end case; end process bcd2sevSeg; -- Disable outputs for all invalid input values oe <= '1' when (bcdInputs < 10) else '0'; a_n <= la_n when oe = '1' else 'Z'; b_n <= lb_n when oe = '1' else 'Z'; c_n <= lc_n when oe = '1' else 'Z'; d_n <= ld_n when oe = '1' else 'Z'; e_n <= le_n when oe = '1' else 'Z'; f_n <= lf_n when oe = '1' else 'Z'; g_n <= lg_n when oe = '1' else 'Z'; end behavioral; library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity sevenSegmentTB is end sevenSegmentTB; architecture testbench of sevenSegmentTB is component sevenSegment port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end component; type vector is record bcdStimulus: std_logic_vector(3 downto 0); sevSegOut: std_logic_vector(6 downto 0); end record; constant NumVectors: integer:= 17; constant PropDelay: time := 40 ns; constant SimLoopDelay: time := 10 ns; type vectorArray is array (0 to NumVectors - 1) of vector; constant vectorTable: vectorArray := ( (bcdStimulus => "0000", sevSegOut => "0000001"), (bcdStimulus => "0001", sevSegOut => "1001111"), (bcdStimulus => "0010", sevSegOut => "0010010"), (bcdStimulus => "0011", sevSegOut => "0000110"), (bcdStimulus => "0100", sevSegOut => "1001100"), (bcdStimulus => "0101", sevSegOut => "0100100"), (bcdStimulus => "0110", sevSegOut => "0100000"), (bcdStimulus => "0111", sevSegOut => "0001111"), (bcdStimulus => "1000", sevSegOut => "0000000"), (bcdStimulus => "1001", sevSegOut => "0000100"), (bcdStimulus => "1010", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1011", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1100", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1101", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1110", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "1111", sevSegOut => "ZZZZZZZ"), (bcdStimulus => "0000", sevSegOut => "0110110") -- this vector fails ); for all : sevenSegment use entity work.sevenSegment(behavioral); signal StimInputs: std_logic_vector(3 downto 0); signal CaptureOutputs: std_logic_vector(6 downto 0); begin u1: sevenSegment port map (bcdInputs => StimInputs, a_n => CaptureOutputs(6), b_n => CaptureOutputs(5), c_n => CaptureOutputs(4), d_n => CaptureOutputs(3), e_n => CaptureOutputs(2), f_n => CaptureOutputs(1), g_n => CaptureOutputs(0)); LoopStim: process variable FoundError: boolean := false; variable TempVector: vector; variable ErrorMsgLine: line; begin for i in vectorTable'range loop TempVector := vectorTable(i); StimInputs <= TempVector.bcdStimulus; wait for PropDelay; if CaptureOutputs /= TempVector.sevSegOut then write (ErrorMsgLine, string'("Vector failed at ")); write (ErrorMsgLine, now); writeline (output, ErrorMsgLine); FoundError := true; end if; wait for SimLoopDelay; end loop; assert FoundError report "No errors. All vectors passed." severity note; wait; end process; end testbench; library ieee; use ieee.std_logic_1164.all; entity sevenSegment is port ( bcdInputs: in std_logic_vector (3 downto 0); a_n, b_n, c_n, d_n, e_n, f_n, g_n: out std_logic ); end sevenSegment; architecture behavioral of sevenSegment is begin bcd2sevSeg: process (bcdInputs) begin -- Assign default to "off" a_n <= '1'; b_n <= '1'; c_n <= '1'; d_n <= '1'; e_n <= '1'; f_n <= '1'; g_n <= '1'; case bcdInputs is when "0000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; when "0001" => b_n <= '0'; c_n <= '0'; when "0010" => a_n <= '0'; b_n <= '0'; d_n <= '0'; e_n <= '0'; g_n <= '0'; when "0011" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; g_n <= '0'; when "0100" => b_n <= '0'; c_n <= '0'; f_n <= '0'; g_n <= '0'; when "0101" => a_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when "0110" => a_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "0111" => a_n <= '0'; b_n <= '0'; c_n <= '0'; when "1000" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; e_n <= '0'; f_n <= '0'; g_n <= '0'; when "1001" => a_n <= '0'; b_n <= '0'; c_n <= '0'; d_n <= '0'; f_n <= '0'; g_n <= '0'; when others => null; end case; end process bcd2sevSeg; end behavioral; library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_unsigned.all; entity ForceShare is port ( a,b,c,d,e,f: in std_logic_vector (7 downto 0); result: out std_logic_vector(7 downto 0) ); end ForceShare; architecture behaviour of ForceShare is begin sum: process (a,c,b,d,e,f) variable tempSum: std_logic_vector(7 downto 0); begin tempSum := a + b; -- temporary node for sum if (tempSum = "10011010") then result <= c; elsif (tempSum = "01011001") then result <= d; elsif (tempSum = "10111011") then result <= e; else result <= f; end if; end process; end behaviour; library IEEE; use IEEE.std_logic_1164.all; entity shifter is port ( clk, rst: in std_logic; shiftEn,shiftIn: std_logic; q: out std_logic_vector (15 downto 0) ); end shifter; architecture behav of shifter is signal qLocal: std_logic_vector(15 downto 0); begin shift: process (clk, rst) begin if (rst = '1') then qLocal <= (others => '0'); elsif (clk'event and clk = '1') then if (shiftEn = '1') then qLocal <= qLocal(14 downto 0) & shiftIn; else qLocal <= qLocal; end if; end if; q <= qLocal; end process; end behav; library ieee; use ieee.std_logic_1164.all; entity lastAssignment is port (a, b: in std_logic; selA, selb: in std_logic; result: out std_logic ); end lastAssignment; architecture behavioral of lastAssignment is begin demo: process (a,b,selA,selB) begin if (selA = '1') then result <= a; else result <= '0'; end if; if (selB = '1') then result <= b; else result <= '0'; end if; end process demo; end behavioral; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '0' then b <= a; else b <= '0'; end if; end process; end basic; library ieee; use ieee.std_logic_1164.all; entity signalDemo is port ( a: in std_logic; b: out std_logic ); end signalDemo; architecture basic of signalDemo is signal c: std_logic; begin demo: process (a) begin c <= a; if c = '1' then b <= a; else b <= '0'; end if; end process; end basic; library IEEE; USE IEEE.std_logic_1164.all; package simPrimitives is component OR2 generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end component; component SimDFF generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end component; end simPrimitives; library IEEE; USE IEEE.std_logic_1164.all; entity OR2 is generic (tPD: time := 1 ns); port (I1, I2: in std_logic; Y: out std_logic ); end OR2; architecture simple of OR2 is begin Y <= I1 OR I2 after tPD; end simple; library IEEE; use IEEE.std_logic_1164.all; entity SimDFF is generic(tCQ: time := 1 ns; tS : time := 1 ns; tH : time := 1 ns ); port (D, Clk: in std_logic; Q: out std_logic ); end SimDff; architecture SimModel of SimDFF is begin reg: process (Clk, D) begin -- Assign output tCQ after rising clock edge if (Clk'event and Clk = '1') then Q <= D after tCQ; end if; -- Check setup time if (Clk'event and Clk = '1') then assert (D'last_event >= tS) report "Setup time violation" severity Warning; end if; -- Check hold time if (D'event and Clk'stable and Clk = '1') then assert (D'last_event - Clk'last_event > tH) report "Hold Time Violation" severity Warning; end if; end process; end simModel; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until rising_edge(clk); if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; entity SRFF is port ( s,r: in std_logic; clk: in std_logic; q: out std_logic ); end SRFF; architecture rtl of SRFF is begin process begin wait until clk = '1'; if s = '0' and r = '1' then q <= '0'; elsif s = '1' and r = '0' then q <= '1'; end if; end process; end rtl; library IEEE; use IEEE.std_logic_1164.all; package scaleable is component scaleUpCnt port ( clk: in std_logic; reset: in std_logic; cnt: in std_logic_vector ); end component; end scaleable; library IEEE; use IEEE.std_logic_1164.all; use work.primitive.all; entity scaleUpCnt is port ( clk: in std_logic; reset: in std_logic; cnt: out std_logic_vector ); end scaleUpCnt; architecture scaleable of scaleUpCnt is signal one: std_logic := '1'; signal cntL: std_logic_vector(cnt'range); signal andTerm: std_logic_vector(cnt'range); begin -- Special case is the least significant bit lsb: tff port map (t => one, reset => reset, clk => clk, q => cntL(cntL'low) ); andTerm(0) <= cntL(cntL'low); -- General case for all other bits genAnd: for i in 1 to cntL'high generate andTerm(i) <= andTerm(i - 1) and cntL(i); end generate; genTFF: for i in 1 to cntL'high generate t1: tff port map (t => andTerm(i), clk => clk, reset => reset, q => cntl(i) ); end generate; cnt <= CntL; end scaleable; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "010"; constant Turn_Ar: targetFsmType := "110"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(3 downto 0); constant Idle: targetFsmType := "0000"; constant B_Busy: targetFsmType := "0001"; constant Backoff: targetFsmType := "0011"; constant S_Data: targetFsmType := "1100"; constant Turn_Ar: targetFsmType := "1101"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "101"; constant Backoff: targetFsmType := "010"; constant S_Data: targetFsmType := "011"; constant Turn_Ar: targetFsmType := "110"; constant Dont_Care: targetFsmType := "XXX"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= Dont_Care; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Stop_n: out std_logic; -- PCI Stop# PCI_Trdy_n: out std_logic; -- PCI Trdy# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; type targetFsmType is (Idle, B_Busy, Backoff, S_Data, Turn_Ar); signal currState, nextState: targetFsmType; begin -- Process to generate next state logic nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; -- Process to register the current state curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; -- Process to generate outputs outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; -- Assign output ports PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; -- Incorporates Errata 10.1 and 10.2 library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(4 downto 0); constant Idle: integer := 0; constant B_Busy: integer := 1; constant Backoff: integer := 2; constant S_Data: integer := 3; constant Turn_Ar: integer := 4; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin nextState <= (others => '0'); if currState(Idle) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; if currState(B_Busy) = '1' then if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState(Idle) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState(S_Data) <= '1'; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState(Backoff) <= '1'; else nextState(B_Busy) <= '1'; end if; end if; if currState(S_Data) = '1' then if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState(Backoff) <= '1'; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState(Turn_Ar) <= '1'; else nextState(S_Data) <= '1'; end if; end if; if currState(Backoff) = '1' then if PCI_Frame_n = '1' then nextState(Turn_Ar) <= '1'; else nextState(Backoff) <= '1'; end if; end if; if currState(Turn_Ar) = '1' then if (PCI_Frame_n = '0' and Hit = '0') then nextState(B_Busy) <= '1'; else nextState(Idle) <= '1'; end if; end if; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= (others => '0'); -- per Errata 10.2 currState(Idle) <= '1'; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; -- defaults per errata 10.1 OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; if (currState(S_Data) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Backoff) = '1') then if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; end if; if (currState(Turn_Ar) = '1') then OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; end if; if (currState(Idle) = '1' or currState(B_Busy) = '1') then OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end if; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when IDLE => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when B_BUSY => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= IDLE; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= BACKOFF; else nextState <= B_BUSY; end if; when S_DATA => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= BACKOFF; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= TURN_AR; else nextState <= S_DATA; end if; when BACKOFF => if PCI_Frame_n = '1' then nextState <= TURN_AR; else nextState <= BACKOFF; end if; when TURN_AR => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_BUSY; else nextState <= IDLE; end if; when others => nextState <= IDLE; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin -- Set default output assignments OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library IEEE; use IEEE.std_logic_1164.all; entity pci_target is port ( PCI_Frame_n: in std_logic; -- PCI Frame# PCI_Irdy_n: in std_logic; -- PCI Irdy# Hit: in std_logic; -- Hit on address decode D_Done: in std_logic; -- Device decode complete Term: in std_logic; -- Terminate transaction Ready: in std_logic; -- Ready to transfer data Cmd_Write: in std_logic; -- Command is Write Cmd_Read: in std_logic; -- Command is Read T_Abort: in std_logic; -- Target error - abort transaction PCI_Clk: in std_logic; -- PCI Clock PCI_Reset_n: in std_logic; -- PCI Reset# PCI_Devsel_n: out std_logic; -- PCI Devsel# PCI_Trdy_n: out std_logic; -- PCI Trdy# PCI_Stop_n: out std_logic; -- PCI Stop# OE_AD: out std_logic; -- PCI AD bus enable OE_Trdy_n: out std_logic; -- PCI Trdy# enable OE_Stop_n: out std_logic; -- PCI Stop# enable OE_Devsel_n: out std_logic -- PCI Devsel# enable ); end pci_target; architecture fsm of pci_target is signal LPCI_Devsel_n, LPCI_Trdy_n, LPCI_Stop_n: std_logic; subtype targetFsmType is std_logic_vector(2 downto 0); constant Idle: targetFsmType := "000"; constant B_Busy: targetFsmType := "001"; constant Backoff: targetFsmType := "011"; constant S_Data: targetFsmType := "110"; constant Turn_Ar: targetFsmType := "100"; signal currState, nextState: targetFsmType; begin nxtStProc: process (currState, PCI_Frame_n, Hit, D_Done, PCI_Irdy_n, LPCI_Trdy_n, LPCI_Devsel_n, LPCI_Stop_n, Term, Ready) begin case currState is when Idle => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when B_Busy => if (PCI_Frame_n ='1' and D_Done = '1') or (PCI_Frame_n = '1' and D_Done = '0' and LPCI_Devsel_n = '0') then nextState <= Idle; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '0' or (Term = '1' and Ready = '1') ) then nextState <= S_Data; elsif (PCI_Frame_n = '0' or PCI_Irdy_n = '0') and Hit = '1' and (Term = '1' and Ready = '0') then nextState <= Backoff; else nextState <= B_Busy; end if; when S_Data => if PCI_Frame_n = '0' and LPCI_Stop_n = '0' and (LPCI_Trdy_n = '1' or PCI_Irdy_n = '0') then nextState <= Backoff; elsif PCI_Frame_n = '1' and (LPCI_Trdy_n = '0' or LPCI_Stop_n = '0') then nextState <= Turn_Ar; else nextState <= S_Data; end if; when Backoff => if PCI_Frame_n = '1' then nextState <= Turn_Ar; else nextState <= Backoff; end if; when Turn_Ar => if (PCI_Frame_n = '0' and Hit = '0') then nextState <= B_Busy; else nextState <= Idle; end if; when others => null; end case; end process nxtStProc; curStProc: process (PCI_Clk, PCI_Reset_n) begin if (PCI_Reset_n = '0') then currState <= Idle; elsif (PCI_Clk'event and PCI_Clk = '1') then currState <= nextState; end if; end process curStProc; outConProc: process (currState, Ready, T_Abort, Cmd_Write, Cmd_Read, T_Abort, Term) begin case currState is when S_Data => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; if (Ready = '1' and T_Abort = '0' and (Cmd_Write = '1' or Cmd_Read = '1')) then LPCI_Trdy_n <= '0'; else LPCI_Trdy_n <= '1'; end if; if (T_Abort = '1' or Term = '1') and (Cmd_Write = '1' or Cmd_Read = '1') then LPCI_Stop_n <= '0'; else LPCI_Stop_n <= '1'; end if; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when Backoff => if (Cmd_Read = '1') then OE_AD <= '1'; else OE_AD <= '0'; end if; LPCI_Stop_n <= '0'; OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; if (T_Abort = '0') then LPCI_Devsel_n <= '0'; else LPCI_Devsel_n <= '1'; end if; when Turn_Ar => OE_Trdy_n <= '1'; OE_Stop_n <= '1'; OE_Devsel_n <= '1'; when others => OE_Trdy_n <= '0'; OE_Stop_n <= '0'; OE_Devsel_n <= '0'; OE_AD <= '0'; LPCI_Trdy_n <= '1'; LPCI_Stop_n <= '1'; LPCI_Devsel_n <= '1'; end case; end process outConProc; PCI_Devsel_n <= LPCI_Devsel_n; PCI_Trdy_n <= LPCI_Trdy_n; PCI_Stop_n <= LPCI_Stop_n; end fsm; library ieee; use ieee.std_logic_1164.all; entity test is port ( a: in std_logic; z: out std_logic; en: in std_logic ); end test; architecture simple of test is begin z <= a when en = '1' else 'z'; end simple;